From 81351422870c467f163c73c5744119d67b4e9f1a Mon Sep 17 00:00:00 2001 From: max Date: Tue, 14 May 2024 16:53:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=96=B0=E5=A2=9E=E5=85=AC=E8=81=8A?= =?UTF-8?q?=E6=96=B0=E6=B6=88=E6=81=AF=E8=BF=87=E6=BB=A4=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=88=E5=8F=AA=E6=8E=A5=E6=94=B6=E6=96=87=E6=9C=AC=E3=80=81?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E3=80=811081=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PublicChatRoomMessageWidget.kt | 5 +--- .../app/public_chat/core/ChatRoomClient.kt | 4 ++- .../public_chat/core/ChatRoomClientManager.kt | 26 +++++++++++++++++++ .../public_chat/core/ChatRoomMessageFilter.kt | 7 +++++ .../PublicChatRoomMessageListPanel.java | 5 ++-- 5 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 app/src/module_public_chat/java/com/chwl/app/public_chat/core/ChatRoomMessageFilter.kt diff --git a/app/src/main/java/com/chwl/app/avroom/public_chat/PublicChatRoomMessageWidget.kt b/app/src/main/java/com/chwl/app/avroom/public_chat/PublicChatRoomMessageWidget.kt index 9d130cfa7..f94c09137 100644 --- a/app/src/main/java/com/chwl/app/avroom/public_chat/PublicChatRoomMessageWidget.kt +++ b/app/src/main/java/com/chwl/app/avroom/public_chat/PublicChatRoomMessageWidget.kt @@ -135,10 +135,7 @@ class PublicChatRoomMessageWidget : FrameLayoutRoomWidget { } private fun filterMessageForMessageList(message: ChatRoomMessage): Boolean { - if (message.msgType == MsgTypeEnum.notification) { - return true - } - if (message.attachment is HeadlineChangedAttachment) { + if (message.msgType == MsgTypeEnum.custom && message.attachment is HeadlineChangedAttachment) { val data = (message.attachment as HeadlineChangedAttachment).headlineData if (data == null || !data.isValid()) { return true diff --git a/app/src/module_public_chat/java/com/chwl/app/public_chat/core/ChatRoomClient.kt b/app/src/module_public_chat/java/com/chwl/app/public_chat/core/ChatRoomClient.kt index 5f6fde38b..67e15a3d0 100644 --- a/app/src/module_public_chat/java/com/chwl/app/public_chat/core/ChatRoomClient.kt +++ b/app/src/module_public_chat/java/com/chwl/app/public_chat/core/ChatRoomClient.kt @@ -42,7 +42,9 @@ open class ChatRoomClient(val sessionId: String) : ICleared, ILog { private val receiveMessageObserver = Observer> { val list = it.filter { item -> - item.sessionId == sessionId + item.sessionId == sessionId && !ChatRoomClientManager.publicChatRoomReceiveMessageFilter.filter( + item + ) } messagePublishSubject.onNext(list) } diff --git a/app/src/module_public_chat/java/com/chwl/app/public_chat/core/ChatRoomClientManager.kt b/app/src/module_public_chat/java/com/chwl/app/public_chat/core/ChatRoomClientManager.kt index 37f0d8650..ede47347f 100644 --- a/app/src/module_public_chat/java/com/chwl/app/public_chat/core/ChatRoomClientManager.kt +++ b/app/src/module_public_chat/java/com/chwl/app/public_chat/core/ChatRoomClientManager.kt @@ -1,11 +1,37 @@ package com.chwl.app.public_chat.core +import com.chwl.core.im.custom.bean.CustomAttachment +import com.chwl.core.im.custom.bean.HeadlineChangedAttachment import com.chwl.core.initial.InitialModel +import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage +import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum object ChatRoomClientManager { private val clients = HashMap() + val publicChatRoomReceiveMessageFilter: ChatRoomMessageFilter = object : ChatRoomMessageFilter { + override fun filter(message: ChatRoomMessage): Boolean { + if (message.msgType == MsgTypeEnum.image || message.msgType == MsgTypeEnum.text) { + return false + } + if (message.msgType == MsgTypeEnum.custom) { + val attachment: CustomAttachment = + (message.attachment as? CustomAttachment) ?: return true + when (attachment.first) { + CustomAttachment.CUSTOM_MSG_HEADLINE_CHANGED -> { + when (attachment.second) { + CustomAttachment.CUSTOM_MSG_HEADLINE_CHANGED_SUB -> { + return false + } + } + } + } + } + return true + } + } + fun getPublicChatClient(): ChatRoomClient? { val sessionId = InitialModel.get().publicChatSessionId return getClient(sessionId) diff --git a/app/src/module_public_chat/java/com/chwl/app/public_chat/core/ChatRoomMessageFilter.kt b/app/src/module_public_chat/java/com/chwl/app/public_chat/core/ChatRoomMessageFilter.kt new file mode 100644 index 000000000..ec6d0cf3f --- /dev/null +++ b/app/src/module_public_chat/java/com/chwl/app/public_chat/core/ChatRoomMessageFilter.kt @@ -0,0 +1,7 @@ +package com.chwl.app.public_chat.core + +import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage + +interface ChatRoomMessageFilter { + fun filter(message: ChatRoomMessage): Boolean +} \ No newline at end of file diff --git a/app/src/module_public_chat/java/com/chwl/app/public_chat/ui/message/PublicChatRoomMessageListPanel.java b/app/src/module_public_chat/java/com/chwl/app/public_chat/ui/message/PublicChatRoomMessageListPanel.java index 23ad6c4c8..ced1aa7a6 100644 --- a/app/src/module_public_chat/java/com/chwl/app/public_chat/ui/message/PublicChatRoomMessageListPanel.java +++ b/app/src/module_public_chat/java/com/chwl/app/public_chat/ui/message/PublicChatRoomMessageListPanel.java @@ -12,6 +12,7 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.chwl.app.R; +import com.chwl.app.public_chat.core.ChatRoomClientManager; import com.chwl.app.public_chat.core.ChatRoomMessageAdapter; import com.chwl.core.im.custom.bean.HeadlineChangedAttachment; import com.chwl.core.module_hall.im.HallAttachment; @@ -368,10 +369,10 @@ public class PublicChatRoomMessageListPanel { } public boolean filterMessage(ChatRoomMessage message) { - if (message.getMsgType() == MsgTypeEnum.notification) { + if (ChatRoomClientManager.INSTANCE.getPublicChatRoomReceiveMessageFilter().filter(message)) { return true; } - if (message.getAttachment() instanceof HeadlineChangedAttachment) { + if (message.getMsgType() == MsgTypeEnum.custom && message.getAttachment() instanceof HeadlineChangedAttachment) { HeadlineBean data = ((HeadlineChangedAttachment) message.getAttachment()).getHeadlineData(); if (data == null || !data.isValid()) { return true;