消息拦截器

This commit is contained in:
18401019693 2022-08-01 10:00:11 +08:00
parent 00de2169b9
commit 91d521c55b
2 changed files with 47 additions and 10 deletions

View File

@ -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;
}
}

View File

@ -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;
/**
@ -62,6 +55,8 @@ public class RongcloudIMManager {
public static void addRongcloudIMOnReceiveMessageListener(RongIMClient.OnReceiveMessageWrapperListener listener) {
mListener = listener;
IMCenter.getInstance().addOnReceiveMessageListener(listener);
//设置消息拦截器
IMCenter.getInstance().setMessageInterceptor(new PDMessageInterceptor());
}
/**