一、功能描述
IM SDK 支持三种类型的消息接收选项:
| 消息接收选项 | 功能描述 |
| TencentCloudChat.TYPES.MSG_REMIND_ACPT_AND_NOTE | 在线时正常接收消息,离线时接收离线推送通知 |
| TencentCloudChat.TYPES.MSG_REMIND_ACPT_NOT_NOTE | SDK 接收消息并通知接入侧(抛出 收到消息事件),接入侧不做提示,一般用于实现“消息免打扰” |
| TencentCloudChat.TYPES.MSG_REMIND_DISCARD | SDK 拒收消息 |
二、setMessageRemindType
接口
chat.setMessageRemindType(options);
参数
参数 options 为 Object 类型,包含的属性值如下:
| 参数 | 类型 | 说明 |
| groupID | String | 群 ID 或 话题 ID |
| userIDList | Array | C2C 会话对端 userID 列表,单次请求的 userID 数不得超过30 |
| messageRemindType | String | 群消息提示类型。详细如下:TencentCloudChat.TYPES.MSG_REMIND_ACPT_AND_NOTE(SDK 接收消息并通知接入侧(抛出 MESSAGE_RECEIVED 事件),接入侧做提示)TencentCloudChat.TYPES.MSG_REMIND_ACPT_NOT_NOTE(SDK 接收消息并通知接入侧(抛出 MESSAGE_RECEIVED 事件),接入侧不做提示,一般用于实现“消息免打扰”)TencentCloudChat.TYPES.MSG_REMIND_DISCARD(SDK 拒收消息) |
返回值
Promise
示例
// 设置拒收群消息(通过 getMessageList 接口可拉取到其他群成员发送的消息)let promise = chat.setMessageRemindType({ groupID: 'group1', messageRemindType: TencentCloudChat.TYPES.MSG_REMIND_DISCARD});promise.then(function(imResponse) { // 设置成功后 SDK 会触发 TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED 事件 // (遍历列表,并读取 Conversation.messageRemindType)}).catch(function(imError) { console.warn('setMessageRemindType error:', imError);});
// 设置拒收群消息后,重新开启新消息提醒let promise = chat.setMessageRemindType({ groupID: 'group1', messageRemindType: TencentCloudChat.TYPES.MSG_REMIND_ACPT_AND_NOTE});promise.then(function(imResponse) { // 设置成功后 SDK 会触发 TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED 事件 // (遍历列表,并读取 Conversation.messageRemindType)}).catch(function(imError) { console.warn('setMessageRemindType error:', imError);});
// C2C 消息免打扰,一般的实现是在线接收消息,离线不接收消息(在有离线推送的情况下)let promise = chat.setMessageRemindType({ userIDList: ['user1', 'user2'], messageRemindType: TencentCloudChat.TYPES.MSG_REMIND_ACPT_NOT_NOTE});promise.then(function(imResponse) { // 设置成功后 SDK 会触发 TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED 事件 //(遍历列表,并读取 Conversation.messageRemindType) const { successUserIDList, failureUserIDList } = imResponse.data; // 删除成功的 userIDList successUserIDList.forEach((item) => { const { userID } = item; }); // 删除失败的 userIDList failureUserIDList.forEach((item) => { const { userID, code, message } = item; });}).catch(function(imError) { console.warn('setMessageRemindType error:', imError);});
// 群消息免打扰,一般的实现是在线接收消息,离线不接收消息(在有离线推送的情况下)let promise = chat.setMessageRemindType({ groupID: 'group1', messageRemindType: TencentCloudChat.TYPES.MSG_REMIND_ACPT_NOT_NOTE });promise.then(function(imResponse) { // 设置消息免打扰成功}).catch(function(imError) { // 设置消息免打扰失败 console.warn('setMessageRemindType error:', imError);});
// 社群话题消息免打扰,一般的实现是在线接收消息,离线不接收消息(在有离线推送的情况下)let promise = chat.setMessageRemindType({ groupID: 'topicID', messageRemindType: TencentCloudChat.TYPES.MSG_REMIND_ACPT_NOT_NOTE});promise.then(function(imResponse) { // 设置消息免打扰成功}).catch(function(imError) { // 设置消息免打扰失败 console.warn('setMessageRemindType error:', imError);});