|
|
@@ -9,6 +9,7 @@ import com.adealink.frame.aab.util.getCompatString
|
|
|
import com.adealink.frame.base.Rlt
|
|
|
import com.adealink.frame.base.fastLazy
|
|
|
import com.adealink.frame.coroutine.dispatcher.Dispatcher
|
|
|
+import com.adealink.frame.data.json.froJsonErrorNull
|
|
|
import com.adealink.frame.ext.findAndSetSpan
|
|
|
import com.adealink.frame.frame.BaseFrame
|
|
|
import com.adealink.frame.image.imageService
|
|
|
@@ -19,6 +20,7 @@ import com.adealink.frame.imkit.model.TAG_IM_UI
|
|
|
import com.adealink.frame.log.Log
|
|
|
import com.adealink.frame.network.ISocketNotify
|
|
|
import com.adealink.frame.network.data.Res
|
|
|
+import com.adealink.frame.storage.cache.TimeoutLruCache
|
|
|
import com.adealink.frame.util.AppUtil
|
|
|
import com.adealink.frame.util.ONE_MINUTE
|
|
|
import com.adealink.weparty.App
|
|
|
@@ -36,6 +38,8 @@ import com.adealink.weparty.message.constant.TAG_IM_MSG_RECEIVE
|
|
|
import com.adealink.weparty.message.constant.TAG_IM_NEW_MSG_NTF
|
|
|
import com.adealink.weparty.message.constant.TAG_MESSAGE
|
|
|
import com.adealink.weparty.message.conversation.ConversationActivity
|
|
|
+import com.adealink.weparty.message.conversation.data.MessageExpansionKey
|
|
|
+import com.adealink.weparty.message.conversation.data.MessageShowInfo
|
|
|
import com.adealink.weparty.message.conversation.message.APP_INFO_MESSAGE_TYPE
|
|
|
import com.adealink.weparty.message.conversation.message.CPInviteMessage
|
|
|
import com.adealink.weparty.message.conversation.message.CP_INVITE_MESSAGE_TYPE
|
|
|
@@ -48,14 +52,20 @@ import com.adealink.weparty.message.userinfo.IMUserInfoManager
|
|
|
import com.adealink.weparty.message.userinfo.UserDataProvider
|
|
|
import com.adealink.weparty.message.userinfo.model.IMUserInfo
|
|
|
import com.adealink.weparty.module.account.AccountModule
|
|
|
+import com.adealink.weparty.module.couple.CoupleModule
|
|
|
import com.adealink.weparty.module.couple.data.CoupleOnlineFloatData
|
|
|
+import com.adealink.weparty.module.couple.data.CoupleUserInfo
|
|
|
+import com.adealink.weparty.module.couple.data.IntimacyValInfo
|
|
|
+import com.adealink.weparty.module.couple.listener.ICoupleListener
|
|
|
import com.adealink.weparty.module.message.data.BatchGetFirstChatTsReq
|
|
|
+import com.adealink.weparty.module.message.data.BatchGetSessionListReq
|
|
|
import com.adealink.weparty.module.message.data.CustomerInfo
|
|
|
import com.adealink.weparty.module.message.data.EnterConversationFrom
|
|
|
import com.adealink.weparty.module.message.data.IMMessageScene
|
|
|
import com.adealink.weparty.module.message.data.Im1v1ContinuousSendMessageDeductNotifyInfo
|
|
|
import com.adealink.weparty.module.message.data.OFFICIAL_TARGET_ID
|
|
|
import com.adealink.weparty.module.message.data.SendQuickMessageReq
|
|
|
+import com.adealink.weparty.module.message.data.SessionInfo
|
|
|
import com.adealink.weparty.module.message.data.isSystemTarget
|
|
|
import com.adealink.weparty.module.profile.ProfileModule
|
|
|
import com.adealink.weparty.module.profile.data.UserInfo
|
|
|
@@ -66,10 +76,12 @@ import com.adealink.weparty.push.data.WeNextPushMessage
|
|
|
import com.adealink.weparty.ui.home.util.HomeUIUtil
|
|
|
import com.adealink.weparty.widget.floatview.FloatViewFactory
|
|
|
import com.facebook.common.util.UriUtil
|
|
|
+import io.rong.imlib.IMessageExpansionListener
|
|
|
import io.rong.imlib.MessageTag
|
|
|
import io.rong.imlib.RongIMClient
|
|
|
import io.rong.imlib.model.Message
|
|
|
import io.rong.imlib.model.MessageContent
|
|
|
+import kotlinx.coroutines.async
|
|
|
import kotlinx.coroutines.delay
|
|
|
import kotlinx.coroutines.launch
|
|
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
|
|
@@ -82,7 +94,7 @@ import com.adealink.weparty.module.message.Message as MESSAGE_ROUTER
|
|
|
val messageManager: IMessageManager by lazy { MessageManager() }
|
|
|
|
|
|
class MessageManager : BaseFrame<IMessageListener>(), IMessageManager,
|
|
|
- UserDataProvider.UserInfoProvider {
|
|
|
+ UserDataProvider.UserInfoProvider, ICoupleListener {
|
|
|
private val messageHttpService by lazy {
|
|
|
App.instance.networkService.getHttpService(MessageHttpService::class.java)
|
|
|
}
|
|
|
@@ -196,6 +208,33 @@ class MessageManager : BaseFrame<IMessageListener>(), IMessageManager,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private val messageExpansionListener = object : RongIMClient.MessageExpansionListener {
|
|
|
+ override fun onMessageExpansionUpdate(
|
|
|
+ expansion: MutableMap<String, String>?,
|
|
|
+ message: Message?
|
|
|
+ ) {
|
|
|
+ message ?: return
|
|
|
+ val blockMessageShowInfoExpansion = expansion?.get(MessageExpansionKey.BlockMessageShowInfo.key)
|
|
|
+ if (blockMessageShowInfoExpansion != null && message.sentStatus != Message.SentStatus.FAILED) {
|
|
|
+ val blockMessageShowInfo = froJsonErrorNull<MessageShowInfo>(blockMessageShowInfoExpansion)
|
|
|
+ if (blockMessageShowInfo?.shouldNotShow() == true) {
|
|
|
+ //被拦截消息不应该显示,设置消息发送状态为发送失败
|
|
|
+ message.sentStatus = Message.SentStatus.FAILED
|
|
|
+ IMService.innerService.setMessageSentStatus(message, null)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onMessageExpansionRemove(
|
|
|
+ keyArray: MutableList<String>?,
|
|
|
+ message: Message?
|
|
|
+ ) {
|
|
|
+ //Ntd.
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
init {
|
|
|
App.instance.networkService.subscribeNotify(notificationMessageNotify)
|
|
|
App.instance.networkService.subscribeNotify(im1v1ContinuousSendMessageDeductNotify)
|
|
|
@@ -205,6 +244,8 @@ class MessageManager : BaseFrame<IMessageListener>(), IMessageManager,
|
|
|
IMUserInfoManager.setUserInfoProvider(this)
|
|
|
IMService.innerService.setMessageInterceptor(messageInterceptor)
|
|
|
IMService.innerService.addOnReceiveMessageListener(onReceiveMessageListener)
|
|
|
+ IMService.innerService.addMessageExpansionListener(messageExpansionListener)
|
|
|
+ CoupleModule.addListener(this)
|
|
|
}
|
|
|
|
|
|
override suspend fun sendQuickMessage(
|
|
|
@@ -517,4 +558,93 @@ class MessageManager : BaseFrame<IMessageListener>(), IMessageManager,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private val sessionInfoCache = TimeoutLruCache<Long, SessionInfo>(500, 5 * 60 * 1000)//最多500个,缓存5分钟
|
|
|
+ override suspend fun batchGetSessionInfo(
|
|
|
+ targetIdSet: Set<Long>,
|
|
|
+ cache: Boolean,
|
|
|
+ fromOnlineList: Boolean
|
|
|
+ ): Map<Long, SessionInfo> {
|
|
|
+ val resultMap = mutableMapOf<Long, SessionInfo>()
|
|
|
+ val idsToFetch = mutableSetOf<Long>()
|
|
|
+
|
|
|
+ if (cache) {
|
|
|
+ for (id in targetIdSet) {
|
|
|
+ val cached = sessionInfoCache[id]
|
|
|
+ if (cached != null) {
|
|
|
+ resultMap[id] = cached
|
|
|
+ if (fromOnlineList) {
|
|
|
+ cached.onlineStatus = 1
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ idsToFetch.add(id)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (idsToFetch.isEmpty()) {
|
|
|
+ return resultMap
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ idsToFetch.addAll(targetIdSet)
|
|
|
+ }
|
|
|
+
|
|
|
+ val sessionInfoListDef = async {
|
|
|
+ messageHttpService.batchGetSessionInfo(BatchGetSessionListReq(idsToFetch.toList()))
|
|
|
+ }
|
|
|
+
|
|
|
+ val sessionInfoRes = sessionInfoListDef.await()
|
|
|
+
|
|
|
+ if (sessionInfoRes !is Rlt.Success) {
|
|
|
+ return resultMap
|
|
|
+ }
|
|
|
+
|
|
|
+ val fetchedSessionInfos = (sessionInfoRes as? Rlt.Success)?.data?.data?.sessionInfos ?: emptyList()
|
|
|
+ for (info in fetchedSessionInfos) {
|
|
|
+ sessionInfoCache.put(info.uid, info)
|
|
|
+ resultMap[info.uid] = info
|
|
|
+ }
|
|
|
+
|
|
|
+ return resultMap
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onAddIntimacyVal(intimacyValInfo: IntimacyValInfo) {
|
|
|
+ super.onAddIntimacyVal(intimacyValInfo)
|
|
|
+ if (!intimacyValInfo.isSelfInvolved()) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ launch {
|
|
|
+ val selfUid = AccountModule.uid
|
|
|
+ val targetUid = arrayListOf(intimacyValInfo.uid, intimacyValInfo.peerUid).apply {
|
|
|
+ remove(selfUid)
|
|
|
+ }.getOrNull(0) ?: return@launch
|
|
|
+ val cache = sessionInfoCache[targetUid]
|
|
|
+ if (cache != null) {
|
|
|
+ val oldIntimacyInfo = cache.userIntimacyInfo ?: return@launch
|
|
|
+ oldIntimacyInfo.exp += intimacyValInfo.value
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onGetMyIntimacyInfos(coupleUserInfos: List<CoupleUserInfo>) {
|
|
|
+ super.onGetMyIntimacyInfos(coupleUserInfos)
|
|
|
+ launch {
|
|
|
+ coupleUserInfos.forEach { newIntimacyInfo ->
|
|
|
+ val cache = sessionInfoCache[newIntimacyInfo.uid]
|
|
|
+ if (cache != null) {
|
|
|
+ val oldIntimacyInfo = cache.userIntimacyInfo
|
|
|
+ if (oldIntimacyInfo == null) {
|
|
|
+ cache.userIntimacyInfo = newIntimacyInfo
|
|
|
+ return@launch
|
|
|
+ }
|
|
|
+ if (oldIntimacyInfo.type != newIntimacyInfo.type
|
|
|
+ && oldIntimacyInfo.friendType != newIntimacyInfo.friendType
|
|
|
+ && oldIntimacyInfo.level != newIntimacyInfo.level
|
|
|
+ && oldIntimacyInfo.exp != newIntimacyInfo.exp
|
|
|
+ ) {
|
|
|
+ cache.userIntimacyInfo = newIntimacyInfo
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|