|
|
@@ -3,7 +3,6 @@ package com.adealink.weparty.message.conversationlist.viewmodel
|
|
|
import androidx.lifecycle.LiveData
|
|
|
import androidx.lifecycle.MediatorLiveData
|
|
|
import androidx.lifecycle.MutableLiveData
|
|
|
-import com.adealink.frame.aab.util.getCompatString
|
|
|
import com.adealink.frame.base.Rlt
|
|
|
import com.adealink.frame.coroutine.dispatcher.Dispatcher
|
|
|
import com.adealink.frame.dot.NumDot
|
|
|
@@ -36,10 +35,10 @@ import com.adealink.weparty.message.conversation.provider.ConversationClickType
|
|
|
import com.adealink.weparty.message.conversationlist.model.BaseUiConversation
|
|
|
import com.adealink.weparty.message.conversationlist.model.SingleConversation
|
|
|
import com.adealink.weparty.message.data.ConversationListType
|
|
|
-import com.adealink.weparty.message.data.NoticeContent
|
|
|
import com.adealink.weparty.message.datasource.remote.MessageHttpService
|
|
|
import com.adealink.weparty.message.event.Event
|
|
|
import com.adealink.weparty.message.listener.IIMUserInfoListener
|
|
|
+import com.adealink.weparty.message.manager.messageManager
|
|
|
import com.adealink.weparty.message.userinfo.IMUserInfoManager
|
|
|
import com.adealink.weparty.message.userinfo.model.IMUserInfo
|
|
|
import com.adealink.weparty.module.message.data.BatchGetSessionListReq
|
|
|
@@ -65,6 +64,7 @@ import io.rong.message.ReadReceiptMessage
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
import kotlinx.coroutines.SupervisorJob
|
|
|
import kotlinx.coroutines.android.asCoroutineDispatcher
|
|
|
+import kotlinx.coroutines.async
|
|
|
import kotlinx.coroutines.cancel
|
|
|
import kotlinx.coroutines.launch
|
|
|
import java.lang.ref.WeakReference
|
|
|
@@ -107,12 +107,6 @@ open class ConversationListViewModel(
|
|
|
val conversationListLiveData: MediatorLiveData<List<BaseUiConversation>>
|
|
|
get() = _conversationListLiveData
|
|
|
|
|
|
- /**
|
|
|
- * 获取连接状态通知内容 LiveData
|
|
|
- */
|
|
|
- val noticeContentLiveData: LiveData<NoticeContent>
|
|
|
- get() = _noticeContentLiveData
|
|
|
-
|
|
|
/**
|
|
|
* 获取刷新事件 LiveData
|
|
|
*/
|
|
|
@@ -124,8 +118,6 @@ open class ConversationListViewModel(
|
|
|
|
|
|
private val connectionStatusLiveData =
|
|
|
MutableLiveData<RongIMClient.ConnectionStatusListener.ConnectionStatus>()
|
|
|
- private val _noticeContentLiveData: MutableLiveData<NoticeContent> =
|
|
|
- MutableLiveData<NoticeContent>()
|
|
|
private val _refreshEventLiveData = MutableLiveData<Event.RefreshEvent>()
|
|
|
private val _loadMoreEnableEventLiveData = MutableLiveData<Event.LoadMoreEnableEvent>()
|
|
|
|
|
|
@@ -341,8 +333,6 @@ open class ConversationListViewModel(
|
|
|
if (status == RongIMClient.ConnectionStatusListener.ConnectionStatus.CONNECTED) {
|
|
|
getConversationList(loadMore = false, isEventManual = false, delayTime = 0)
|
|
|
}
|
|
|
- // 更新连接状态通知信息
|
|
|
- updateNoticeContent(status)
|
|
|
preConnectionStatus = status
|
|
|
}
|
|
|
|
|
|
@@ -389,7 +379,6 @@ open class ConversationListViewModel(
|
|
|
IMService.innerService.addConversationEventListener(conversationEventListener)
|
|
|
IMService.innerService.addMessageEventListener(messageEventListener)
|
|
|
IMService.innerService.addCancelSendMediaMessageListener(cancelSendMediaMessageListener)
|
|
|
- updateNoticeContent(IMService.innerService.getCurrentConnectionStatus())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -650,9 +639,16 @@ open class ConversationListViewModel(
|
|
|
|
|
|
private fun batchGetTargetExtraInfo(targetIds: Set<Long>) {
|
|
|
viewModelScope.launch {
|
|
|
- val sessionInfoListRes = messageHttpService.batchGetSessionInfo(
|
|
|
- BatchGetSessionListReq(targetIds.toList())
|
|
|
- )
|
|
|
+ val sessionInfoListDef = async {
|
|
|
+ messageHttpService.batchGetSessionInfo(
|
|
|
+ BatchGetSessionListReq(targetIds.toList())
|
|
|
+ )
|
|
|
+ }
|
|
|
+ val customerListDef = async {
|
|
|
+ messageManager.getCustomerList(cache = true)
|
|
|
+ }
|
|
|
+ val sessionInfoListRes = sessionInfoListDef.await()
|
|
|
+ val customerIdSet = customerListDef.await()?.map { it.customerUid }?.toSet() ?: setOf()
|
|
|
if (sessionInfoListRes is Rlt.Failed) {
|
|
|
val uid2UserInfo =
|
|
|
(ProfileModule.getUsersInfoByUid(targetIds, true) as? Rlt.Success)?.data
|
|
|
@@ -661,6 +657,7 @@ open class ConversationListViewModel(
|
|
|
val targetIdLong = uiConversation.targetId.safeToLong(0)
|
|
|
val userInfo = uid2UserInfo?.get(targetIdLong) ?: continue
|
|
|
baseUiConversation?.onUserInfoUpdate(IMUserInfo(userInfo))
|
|
|
+ baseUiConversation?.onCustomerUpdate(customerIdSet.contains(targetIdLong))
|
|
|
}
|
|
|
refreshConversationList()
|
|
|
return@launch
|
|
|
@@ -684,6 +681,7 @@ open class ConversationListViewModel(
|
|
|
baseUiConversation?.onUserInfoUpdate(IMUserInfo(userInfo))
|
|
|
baseUiConversation?.onOnlineInRoomStatusUpdate(onlineInRoomStatus)
|
|
|
baseUiConversation?.onCoupleUserInfoUpdate(sessionInfo.userIntimacyInfo)
|
|
|
+ baseUiConversation?.onCustomerUpdate(customerIdSet.contains(targetIdLong))
|
|
|
}
|
|
|
refreshConversationList()
|
|
|
}
|
|
|
@@ -1024,64 +1022,6 @@ open class ConversationListViewModel(
|
|
|
IMService.innerService.removeCancelSendMediaMessageListener(cancelSendMediaMessageListener)
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 更新连接状态通知
|
|
|
- *
|
|
|
- * @param status
|
|
|
- */
|
|
|
- private fun updateNoticeContent(status: RongIMClient.ConnectionStatusListener.ConnectionStatus) {
|
|
|
- if (status == preConnectionStatus) {
|
|
|
- return
|
|
|
- }
|
|
|
- val noticeContent = NoticeContent()
|
|
|
- var content: String? = null
|
|
|
- var isShowContent = true
|
|
|
- var resId = 0
|
|
|
-
|
|
|
- if (!IMConfigCenter.conversationListConfig.isEnableConnectStateNotice) {
|
|
|
- Log.e(TAG_IM_CONV_LIST_VM, "isEnableConnectStateNotice is disabled.")
|
|
|
- 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
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- noticeContent.content = content
|
|
|
- noticeContent.isShowNotice = isShowContent
|
|
|
- noticeContent.iconResId = resId
|
|
|
-
|
|
|
- _noticeContentLiveData.postValue(noticeContent)
|
|
|
- }
|
|
|
-
|
|
|
protected fun refreshConversationList() {
|
|
|
removeDupData()
|
|
|
_conversationListLiveData.send(uiConversationList)
|