From 91d521c55bb6ac942292701b5b2c6b23f321d09d Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Mon, 1 Aug 2022 10:00:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8B=A6=E6=88=AA=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../imrongcloud/PDMessageInterceptor.java | 42 +++++++++++++++++++ .../imrongcloud/RongcloudIMManager.java | 15 +++---- 2 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 common/src/main/java/com/yunbao/common/manager/imrongcloud/PDMessageInterceptor.java diff --git a/common/src/main/java/com/yunbao/common/manager/imrongcloud/PDMessageInterceptor.java b/common/src/main/java/com/yunbao/common/manager/imrongcloud/PDMessageInterceptor.java new file mode 100644 index 000000000..d7b1ba23c --- /dev/null +++ b/common/src/main/java/com/yunbao/common/manager/imrongcloud/PDMessageInterceptor.java @@ -0,0 +1,42 @@ +package com.yunbao.common.manager.imrongcloud; + +import android.util.Log; + +import io.rong.imkit.IMCenter; +import io.rong.imkit.MessageInterceptor; +import io.rong.imlib.model.Conversation; +import io.rong.imlib.model.Message; +import io.rong.message.TextMessage; + +/** + * 消息拦截器 + */ +public class PDMessageInterceptor implements MessageInterceptor { + @Override + public boolean interceptReceivedMessage(Message message, int left, boolean hasPackage, boolean offline) { + if (message.getContent() instanceof TextMessage) { + TextMessage textMessage = (TextMessage) message.getContent(); + String context = textMessage.getContent(); + //符合条件的接受消息不做展示 + if (context.contains("LivePK")) { + Message[] messages = new Message[]{message}; + Log.e("PDMessageInterceptor", textMessage.getContent()); + //删除消息 + IMCenter.getInstance().deleteRemoteMessages(Conversation.ConversationType.PRIVATE, message.getTargetId(), messages, null); + IMCenter.getInstance().clearMessagesUnreadStatus(Conversation.ConversationType.PRIVATE, message.getTargetId(), null); +// return true; + } + } + return false; + } + + @Override + public boolean interceptOnSendMessage(Message message) { + return false; + } + + @Override + public boolean interceptOnSentMessage(Message message) { + return false; + } +} diff --git a/common/src/main/java/com/yunbao/common/manager/imrongcloud/RongcloudIMManager.java b/common/src/main/java/com/yunbao/common/manager/imrongcloud/RongcloudIMManager.java index 1e8bb70d4..76e329187 100644 --- a/common/src/main/java/com/yunbao/common/manager/imrongcloud/RongcloudIMManager.java +++ b/common/src/main/java/com/yunbao/common/manager/imrongcloud/RongcloudIMManager.java @@ -10,27 +10,20 @@ import androidx.annotation.NonNull; import com.bumptech.glide.Glide; import com.bumptech.glide.load.resource.bitmap.CircleCrop; import com.bumptech.glide.request.RequestOptions; -import com.yunbao.common.Constants; -import com.yunbao.common.CommonAppConfig; -import com.yunbao.common.bean.BaseModel; import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.event.RongIMConnectionStatusEvent; import com.yunbao.common.manager.IMLoginManager; import org.greenrobot.eventbus.EventBus; -import cn.rongcloud.rtc.api.RCRTCEngine; import io.rong.imkit.GlideKitImageEngine; import io.rong.imkit.IMCenter; import io.rong.imkit.RongIM; import io.rong.imkit.config.RongConfigCenter; -import io.rong.imlib.RongCoreClient; import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; import io.rong.imlib.model.Message; -import io.rong.message.TextMessage; -import static com.yunbao.common.CommonAppContext.Ingroup; import static com.yunbao.common.CommonAppContext.isReady; /** @@ -54,7 +47,7 @@ public class RongcloudIMManager { initPhotoGlide(); } - private static RongIMClient.OnReceiveMessageWrapperListener mListener ; + private static RongIMClient.OnReceiveMessageWrapperListener mListener; /** * 设置消息接受监听器 @@ -62,14 +55,16 @@ public class RongcloudIMManager { public static void addRongcloudIMOnReceiveMessageListener(RongIMClient.OnReceiveMessageWrapperListener listener) { mListener = listener; IMCenter.getInstance().addOnReceiveMessageListener(listener); + //设置消息拦截器 + IMCenter.getInstance().setMessageInterceptor(new PDMessageInterceptor()); } /** * 移除消息接受监听器 */ public static void removeRongcloudIMOnReceiveMessageListener() { - if (null!=mListener) - IMCenter.getInstance().removeOnReceiveMessageListener(mListener); + if (null != mListener) + IMCenter.getInstance().removeOnReceiveMessageListener(mListener); } /**