|
|
@@ -48,7 +48,8 @@ import kotlinx.coroutines.launch
|
|
|
import java.lang.ref.WeakReference
|
|
|
import java.util.concurrent.CopyOnWriteArrayList
|
|
|
|
|
|
-open class ConversationListViewModel : BaseViewModel(),
|
|
|
+open class ConversationListViewModel(private val isConversationListScene: Boolean = true) :
|
|
|
+ BaseViewModel(),
|
|
|
IIMUserInfoListener, CoroutineScope {
|
|
|
val serialHandler = Dispatcher.getSerialHandler()
|
|
|
override val coroutineContext = SupervisorJob() + serialHandler.asCoroutineDispatcher()
|
|
|
@@ -60,6 +61,7 @@ open class ConversationListViewModel : BaseViewModel(),
|
|
|
IMConfigCenter.conversationListConfig.getDataProcessor().supportedTypes()
|
|
|
private var sizePerPage: Int
|
|
|
private var pageLimit: Int
|
|
|
+
|
|
|
/** 是否优先显示置顶会话(查询结果的排序方式,是否置顶优先,true 表示置顶会话优先返回,false 结果只以会话时间排序) */
|
|
|
private var isTopPriority: Boolean
|
|
|
private var uiConversationList = CopyOnWriteArrayList<BaseUiConversation>()
|
|
|
@@ -333,17 +335,21 @@ open class ConversationListViewModel : BaseViewModel(),
|
|
|
isTopPriority = IMConfigCenter.conversationListConfig.topPriority
|
|
|
|
|
|
_conversationListLiveData = MediatorLiveData<List<BaseUiConversation>>()
|
|
|
- IMUserInfoManager.addListener(this)
|
|
|
- IMService.innerService.addAsyncOnReceiveMessageListener(onReceiveMessageListener)
|
|
|
- IMService.innerService.addConnectionStatusListener(connectionStatusListener)
|
|
|
- IMService.innerService.addConversationStatusListener(conversationStatusListener)
|
|
|
- IMService.innerService.addReadReceiptListener(readReceiptListener)
|
|
|
- IMService.innerService.addSyncConversationReadStatusListener(syncConversationReadStatusListener)
|
|
|
- IMService.innerService.addOnRecallMessageListener(onRecallMessageListener)
|
|
|
- IMService.innerService.addConversationEventListener(conversationEventListener)
|
|
|
- IMService.innerService.addMessageEventListener(messageEventListener)
|
|
|
- IMService.innerService.addCancelSendMediaMessageListener(cancelSendMediaMessageListener)
|
|
|
- updateNoticeContent(IMService.innerService.getCurrentConnectionStatus())
|
|
|
+ if (isConversationListScene) {
|
|
|
+ IMUserInfoManager.addListener(this)
|
|
|
+ IMService.innerService.addAsyncOnReceiveMessageListener(onReceiveMessageListener)
|
|
|
+ IMService.innerService.addConnectionStatusListener(connectionStatusListener)
|
|
|
+ IMService.innerService.addConversationStatusListener(conversationStatusListener)
|
|
|
+ IMService.innerService.addReadReceiptListener(readReceiptListener)
|
|
|
+ IMService.innerService.addSyncConversationReadStatusListener(
|
|
|
+ syncConversationReadStatusListener
|
|
|
+ )
|
|
|
+ IMService.innerService.addOnRecallMessageListener(onRecallMessageListener)
|
|
|
+ IMService.innerService.addConversationEventListener(conversationEventListener)
|
|
|
+ IMService.innerService.addMessageEventListener(messageEventListener)
|
|
|
+ IMService.innerService.addCancelSendMediaMessageListener(cancelSendMediaMessageListener)
|
|
|
+ updateNoticeContent(IMService.innerService.getCurrentConnectionStatus())
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -420,14 +426,20 @@ open class ConversationListViewModel : BaseViewModel(),
|
|
|
refreshConversationList()
|
|
|
return@post
|
|
|
}
|
|
|
- LogUtil.d(TAG_IM_CONVERSATION_VM, "getConversationListByPage. size:" + conversations.size)
|
|
|
+ LogUtil.d(
|
|
|
+ TAG_IM_CONVERSATION_VM,
|
|
|
+ "getConversationListByPage. size:" + conversations.size
|
|
|
+ )
|
|
|
val copyList =
|
|
|
CopyOnWriteArrayList(conversations)
|
|
|
val filterResult: List<Conversation> = dataFilter.filtered(copyList)
|
|
|
if (filterResult.isNotEmpty()) {
|
|
|
for (conversation in filterResult) {
|
|
|
val oldItem: BaseUiConversation? =
|
|
|
- findConversationFromList(conversation.conversationType, conversation.targetId)
|
|
|
+ findConversationFromList(
|
|
|
+ conversation.conversationType,
|
|
|
+ conversation.targetId
|
|
|
+ )
|
|
|
if (oldItem != null) {
|
|
|
oldItem.onConversationUpdate(conversation)
|
|
|
} else {
|
|
|
@@ -457,7 +469,10 @@ open class ConversationListViewModel : BaseViewModel(),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- protected fun findConversationFromList(conversationType: Conversation.ConversationType, targetId: String): BaseUiConversation? {
|
|
|
+ protected fun findConversationFromList(
|
|
|
+ conversationType: Conversation.ConversationType,
|
|
|
+ targetId: String
|
|
|
+ ): BaseUiConversation? {
|
|
|
val baseUiConversationArrayList: List<BaseUiConversation> =
|
|
|
ArrayList<BaseUiConversation>(this.uiConversationList)
|
|
|
for (i in baseUiConversationArrayList.indices.reversed()) {
|
|
|
@@ -487,11 +502,11 @@ open class ConversationListViewModel : BaseViewModel(),
|
|
|
private fun getDeletedMsgConversation(
|
|
|
type: Conversation.ConversationType, targetId: String, deleteMsgId: IntArray
|
|
|
) {
|
|
|
- RongIMClient.getInstance()
|
|
|
+ IMService.innerService
|
|
|
.getConversation(
|
|
|
type,
|
|
|
targetId,
|
|
|
- object : RongIMClient.ResultCallback<Conversation>() {
|
|
|
+ object : RongIMClient.ResultCallback<Conversation?>() {
|
|
|
override fun onSuccess(conversation: Conversation?) {
|
|
|
if (conversation == null) {
|
|
|
return
|
|
|
@@ -508,7 +523,10 @@ open class ConversationListViewModel : BaseViewModel(),
|
|
|
}
|
|
|
}
|
|
|
serialHandler.post {
|
|
|
- if (conversation.sentStatus == Message.SentStatus.FAILED && ResendManager.needResend(conversation.latestMessageId)) {
|
|
|
+ if (conversation.sentStatus == Message.SentStatus.FAILED && ResendManager.needResend(
|
|
|
+ conversation.latestMessageId
|
|
|
+ )
|
|
|
+ ) {
|
|
|
conversation.sentStatus = Message.SentStatus.SENDING
|
|
|
}
|
|
|
updateByConversation(conversation)
|
|
|
@@ -556,6 +574,39 @@ open class ConversationListViewModel : BaseViewModel(),
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
+ fun isConversationToTop(cId: ConversationIdentifier): LiveData<Boolean> {
|
|
|
+ val liveData = MutableLiveData<Boolean>()
|
|
|
+ viewModelScope.launch {
|
|
|
+ IMService.innerService
|
|
|
+ .isConversationToTop(
|
|
|
+ cId,
|
|
|
+ object : IRongCoreCallback.ResultCallback<Boolean>() {
|
|
|
+ override fun onSuccess(t: Boolean?) {
|
|
|
+ liveData.send(t == true)
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onError(e: IRongCoreEnum.CoreErrorCode?) {
|
|
|
+ liveData.send(false)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ return liveData
|
|
|
+ }
|
|
|
+
|
|
|
+ fun setConversationToTop(
|
|
|
+ cId: ConversationIdentifier,
|
|
|
+ isTop: Boolean
|
|
|
+ ) {
|
|
|
+ IMService.innerService
|
|
|
+ .setConversationToTop(
|
|
|
+ cId,
|
|
|
+ isTop,
|
|
|
+ null
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
fun onViewClick(clickType: Int, data: BaseUiConversation) {
|
|
|
when (clickType) {
|
|
|
ConversationClickType.READ_CLICK -> {
|
|
|
@@ -570,43 +621,67 @@ open class ConversationListViewModel : BaseViewModel(),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- fun onPinClick(data: BaseUiConversation) {
|
|
|
+ fun deleteConversation(data: BaseUiConversation) {
|
|
|
val cId = data.conversationIdentifier ?: return
|
|
|
+ IMService.innerService.setConversationToTop(cId, false, null)
|
|
|
+ IMService.innerService.removeConversation(cId.type, cId.targetId, null)
|
|
|
IMService.innerService
|
|
|
- .setConversationToTop(
|
|
|
- cId,
|
|
|
- !data.conversation.isTop,
|
|
|
- object : RongIMClient.ResultCallback<Boolean>() {
|
|
|
- override fun onSuccess(aBoolean: Boolean) {
|
|
|
+ .cleanHistoryMessages(cId, data.conversation.sentTime, true, null)
|
|
|
+ }
|
|
|
|
|
|
+ fun deleteConversation(cId: ConversationIdentifier) {
|
|
|
+ viewModelScope.launch(Dispatcher.WENEXT_THREAD_POOL) {
|
|
|
+ IMService.innerService.getConversation(
|
|
|
+ cId.type,
|
|
|
+ cId.targetId,
|
|
|
+ object : RongIMClient.ResultCallback<Conversation?>() {
|
|
|
+ override fun onSuccess(conversation: Conversation?) {
|
|
|
+ if (conversation != null) {
|
|
|
+ IMService.innerService.setConversationToTop(cId, false, null)
|
|
|
+ IMService.innerService.removeConversation(cId.type, cId.targetId, null)
|
|
|
+ IMService.innerService
|
|
|
+ .cleanHistoryMessages(cId, conversation.sentTime, true, null)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- override fun onError(errorCode: RongIMClient.ErrorCode) {
|
|
|
+ override fun onError(e: RongIMClient.ErrorCode?) {
|
|
|
|
|
|
}
|
|
|
+
|
|
|
})
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- fun onReadClick(data: BaseUiConversation) {
|
|
|
+ fun readAllUnreadConversation() {
|
|
|
+ IMService.innerService.getUnreadConversationList(
|
|
|
+ object : IRongCoreCallback.ResultCallback<List<Conversation>>() {
|
|
|
+ override fun onSuccess(conversations: List<Conversation>) {
|
|
|
+ for (conversation in conversations) {
|
|
|
+ IMService.innerService.clearMessagesUnreadStatus(
|
|
|
+ conversation.conversationType,
|
|
|
+ conversation.targetId,
|
|
|
+ null
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onError(e: IRongCoreEnum.CoreErrorCode?) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+ *IMConfigCenter.conversationListConfig.getDataProcessor().supportedTypes()
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun onPinClick(data: BaseUiConversation) {
|
|
|
val cId = data.conversationIdentifier ?: return
|
|
|
- IMService.innerService.clearMessagesUnreadStatus(cId, null)
|
|
|
+ setConversationToTop(cId, !data.conversation.isTop)
|
|
|
}
|
|
|
|
|
|
- fun deleteConversation(data: BaseUiConversation) {
|
|
|
- //删除会话同时要取消置顶
|
|
|
- val cId = data.conversationIdentifier?: return
|
|
|
- IMService.innerService
|
|
|
- .setConversationToTop(
|
|
|
- cId,
|
|
|
- false,
|
|
|
- null
|
|
|
- )
|
|
|
- IMService.innerService
|
|
|
- .removeConversation(
|
|
|
- data.conversation.conversationType,
|
|
|
- data.conversation.targetId,
|
|
|
- null
|
|
|
- )
|
|
|
+ private fun onReadClick(data: BaseUiConversation) {
|
|
|
+ val cId = data.conversationIdentifier ?: return
|
|
|
+ IMService.innerService.clearMessagesUnreadStatus(cId, null)
|
|
|
}
|
|
|
|
|
|
override fun onCleared() {
|
|
|
@@ -620,7 +695,9 @@ open class ConversationListViewModel : BaseViewModel(),
|
|
|
IMService.innerService.removeReadReceiptListener(readReceiptListener)
|
|
|
IMService.innerService.removeOnRecallMessageListener(onRecallMessageListener)
|
|
|
IMService.innerService.removeConversationEventListener(conversationEventListener)
|
|
|
- IMService.innerService.removeSyncConversationReadStatusListeners(syncConversationReadStatusListener)
|
|
|
+ IMService.innerService.removeSyncConversationReadStatusListeners(
|
|
|
+ syncConversationReadStatusListener
|
|
|
+ )
|
|
|
IMService.innerService.removeCancelSendMediaMessageListener(cancelSendMediaMessageListener)
|
|
|
}
|
|
|
|
|
|
@@ -642,29 +719,37 @@ open class ConversationListViewModel : BaseViewModel(),
|
|
|
LogUtil.e(TAG_IM_CONVERSATION_VM, "rc_is_show_warning_notification is disabled.")
|
|
|
return
|
|
|
}
|
|
|
- if (status == RongIMClient.ConnectionStatusListener.ConnectionStatus.NETWORK_UNAVAILABLE) {
|
|
|
- content = getCompatString(R.string.rc_conversation_list_notice_network_unavailable)
|
|
|
- resId = R.drawable.im_ic_error_notice
|
|
|
- } else if (status == RongIMClient.ConnectionStatusListener.ConnectionStatus.KICKED_OFFLINE_BY_OTHER_CLIENT) {
|
|
|
- content = getCompatString(R.string.rc_conversation_list_notice_kicked)
|
|
|
- resId = R.drawable.im_ic_error_notice
|
|
|
- } else if (status == RongIMClient.ConnectionStatusListener.ConnectionStatus.CONNECTED) {
|
|
|
- isShowContent = false
|
|
|
- } else if (status == RongIMClient.ConnectionStatusListener.ConnectionStatus.UNCONNECTED) {
|
|
|
- content = getCompatString(R.string.rc_conversation_list_notice_disconnect)
|
|
|
- resId = R.drawable.im_ic_error_notice
|
|
|
- } else if (status == RongIMClient.ConnectionStatusListener.ConnectionStatus.CONNECTING || status == RongIMClient.ConnectionStatusListener.ConnectionStatus.SUSPEND) {
|
|
|
- content = getCompatString(R.string.rc_conversation_list_notice_connecting)
|
|
|
- resId = R.drawable.im_conversationlist_notice_connecting_animated
|
|
|
- } else if (status == RongIMClient.ConnectionStatusListener.ConnectionStatus.CONNECTION_STATUS_PROXY_UNAVAILABLE) {
|
|
|
- content = getCompatString(R.string.rc_conversation_list_notice_proxy_unavailable)
|
|
|
- resId = R.drawable.im_ic_error_notice
|
|
|
- } else {
|
|
|
- if (preConnectionStatus == RongIMClient.ConnectionStatusListener.ConnectionStatus.CONNECTION_STATUS_PROXY_UNAVAILABLE) {
|
|
|
- return
|
|
|
+ when (status) {
|
|
|
+ RongIMClient.ConnectionStatusListener.ConnectionStatus.NETWORK_UNAVAILABLE -> {
|
|
|
+ content = getCompatString(R.string.rc_conversation_list_notice_network_unavailable)
|
|
|
+ resId = R.drawable.im_ic_error_notice
|
|
|
+ }
|
|
|
+ RongIMClient.ConnectionStatusListener.ConnectionStatus.KICKED_OFFLINE_BY_OTHER_CLIENT -> {
|
|
|
+ content = getCompatString(R.string.rc_conversation_list_notice_kicked)
|
|
|
+ resId = R.drawable.im_ic_error_notice
|
|
|
+ }
|
|
|
+ RongIMClient.ConnectionStatusListener.ConnectionStatus.CONNECTED -> {
|
|
|
+ isShowContent = false
|
|
|
+ }
|
|
|
+ RongIMClient.ConnectionStatusListener.ConnectionStatus.UNCONNECTED -> {
|
|
|
+ content = getCompatString(R.string.rc_conversation_list_notice_disconnect)
|
|
|
+ resId = R.drawable.im_ic_error_notice
|
|
|
+ }
|
|
|
+ RongIMClient.ConnectionStatusListener.ConnectionStatus.CONNECTING, RongIMClient.ConnectionStatusListener.ConnectionStatus.SUSPEND -> {
|
|
|
+ content = getCompatString(R.string.rc_conversation_list_notice_connecting)
|
|
|
+ resId = R.drawable.im_conversationlist_notice_connecting_animated
|
|
|
+ }
|
|
|
+ RongIMClient.ConnectionStatusListener.ConnectionStatus.CONNECTION_STATUS_PROXY_UNAVAILABLE -> {
|
|
|
+ content = getCompatString(R.string.rc_conversation_list_notice_proxy_unavailable)
|
|
|
+ resId = R.drawable.im_ic_error_notice
|
|
|
+ }
|
|
|
+ else -> {
|
|
|
+ if (preConnectionStatus == RongIMClient.ConnectionStatusListener.ConnectionStatus.CONNECTION_STATUS_PROXY_UNAVAILABLE) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ content = getCompatString(R.string.rc_conversation_list_notice_network_unavailable)
|
|
|
+ resId = R.drawable.im_ic_error_notice
|
|
|
}
|
|
|
- content = getCompatString(R.string.rc_conversation_list_notice_network_unavailable)
|
|
|
- resId = R.drawable.im_ic_error_notice
|
|
|
}
|
|
|
|
|
|
noticeContent.content = content
|
|
|
@@ -712,24 +797,6 @@ open class ConversationListViewModel : BaseViewModel(),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- fun readAllUnreadConversation() {
|
|
|
- IMService.innerService.getUnreadConversationList(
|
|
|
- object : IRongCoreCallback.ResultCallback<List<Conversation>>() {
|
|
|
- override fun onSuccess(conversations: List<Conversation>) {
|
|
|
- for (conversation in conversations) {
|
|
|
- IMService.innerService.clearMessagesUnreadStatus(conversation.conversationType, conversation.targetId, null)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- override fun onError(e: IRongCoreEnum.CoreErrorCode?) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- },
|
|
|
- *IMConfigCenter.conversationListConfig.getDataProcessor().supportedTypes()
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
private inner class GetConversationListRunnable(
|
|
|
private val viewModel: ConversationListViewModel,
|
|
|
val loadMore: Boolean,
|