消息拦截器
This commit is contained in:
parent
00de2169b9
commit
91d521c55b
@ -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;
|
||||
}
|
||||
}
|
@ -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,13 +55,15 @@ 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)
|
||||
if (null != mListener)
|
||||
IMCenter.getInstance().removeOnReceiveMessageListener(mListener);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user