logo
即时通讯
当前页

设置会话免打扰


功能概述

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

消息免打扰.png

开启免打扰

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

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

const status = 2;  // 将会话状态设置为免打扰 
const conversationID = '';
const conversationType = 2;  // 会话类型为群聊
zim.setConversationNotificationStatus(status, conversationID, conversationType)
    .then((res: ZIMConversationNotificationStatusSetResult) => {
        // 操作成功
    })
    .catch((err: ZIMError) => {
        // 操作失败
    });

获取免打扰状态

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

// 1. 监听会话变更事件
zim.on('conversationChanged', (zim: ZIM, data: ZIMEventOfConversationChangedResult) => {
    console.log(data.infoList[0].conversation.notificationStatus);
});

// 2. 查询会话列表
const config: ZIMConversationQueryConfig = { count: 10, nextConversation: null };
zim.queryConversationList(config, null)
    .then((res: ZIMConversationListQueriedResult) => {
        // 查询成功
        console.log(res.conversationList[0].notificationStatus);
    })
    .catch((err: ZIMError) => {
        // 查询失败
    });

Previous

管理消息未读数

Next

删除会话

当前页

返回到顶部