logo
当前页

设置会话免打扰


功能概述

会话消息免打扰,指设置之后,SDK 在接收到当前会话的消息时,将不会进行推送通知,同时 “消息未读总数”也不会增加

消息免打扰.png

开启免打扰

调用 setConversationNotificationStatus 接口,传入 conversationID 指定某个会话,设置消息免打扰功能。

// 将某个会话设置为消息免打扰状态
// 以单聊会话为例

// 设置会话类型为单聊
ZIMConversationType conversationType = ZIMConversationType.PEER;

// 设置会话为免打扰
zim.setConversationNotificationStatus(ZIMConversationNotificationStatus.DO_NOT_DISTURB, "CONV_ID", conversationType, new ZIMConversationNotificationStatusSetCallback() {
    @Override
    public void onConversationNotificationStatusSet(ZIMError errorInfo) {
        // 设置消息免打扰的结果
        if(errorInfo.code == ZIMErrorCodeSuccess) {
          // ......
        } else {
          // ......
        }  
    }
});

获取免打扰状态

设置免打扰后,客户端本地存在该会话的操作端和多端在线设备,都将会收到 onConversationChanged 通知事件。 离线设备重新登录后,可通过查询会话列表的 ZIMConversation.notificationStatus 属性获取会话免打扰状态。

// 1. 监听会话变更事件
public void onConversationChanged(ZIM zim, ArrayList<ZIMConversationChangeInfo> conversationChangeInfoList) {
    super.onConversationChanged(zim, conversationChangeInfoList);
    // conversationChangeInfoList.get(0).conversation.notificationStatus
}

// 2. 查询会话列表
ZIMConversationQueryConfig config = new ZIMConversationQueryConfig();
config.count = 10;
config.nextConversation = null;

zim.queryConversationList(config, new ZIMConversationListQueriedCallback() {
    @Override
    public void onConversationListQueried(ArrayList<ZIMConversation> conversationList, ZIMError errorInfo) {
        // 获取会话列表查询结果
        if(errorInfo.code == ZIMErrorCode.SUCCESS) {
          // conversationList.get(0).notificationStatus
        } else {
          // ......
        }      
    }
});

Previous

管理消息未读数

Next

删除会话

当前页

返回到顶部