tim.setMessageRead(options);
options
parameter is of the Object
type. It contains the following attribute values:Name | Type | Description |
conversationID | String | Conversation ID. Valid values: C2C${userID} (for a one-to-one chat) GROUP{groupID} (for a group chat) @TIM#SYSTEM (for a system notification conversation) GROUP${topicID} (for a topic) |
Promise
// Set all the unread messages in a conversation as readlet promise = chat.setMessageRead({conversationID: 'C2Cexample'});promise.then(function(imResponse) {// Set the unread messages as read successfully.// The value of the `unreadCount` attribute of the conversation with the specified ID is set to `0`.}).catch(function(imError) {// Failed to set the unread messages as readconsole.warn('setMessageRead error:', imError);});
chat.setAllMessageRead(options);
options
parameter is of the Object
type. It contains the following attribute values:Name | Type | Description |
scope | String | undefined | Set the scope of message processing. Valid values: TencentCloudChat.TYPES.READ_ALL_C2C_MSG: set the unread messages of all the one-to-one conversations as read TencentCloudChat.TYPES.READ_ALL_GROUP_MSG: set the unread messages of all the group conversations as read TencentCloudChat.TYPES.READ_ALL_MSG (default value): set the unread messages of all the one-to-one and group conversations as read |
Promise
// Set the unread messages of all the conversations as read// Same as `chat.setAllMessageRead({scope: TencentCloudChat.TYPES.READ_ALL_MSG})`let promise = chat.setAllMessageRead();promise.then(function(imResponse) {// Set the unread messages as read successfully.// The values of the `unreadCount` attribute of all the conversations are set to `0`.}).catch(function(imError) {// Failed to set the unread messages as readconsole.warn('setAllMessageRead error:', imError);});
// Set the unread messages of all the one-to-one conversations as readlet promise = chat.setAllMessageRead({scope: TencentCloudChat.TYPES.READ_ALL_C2C_MSG});promise.then(function(imResponse) {// Set the unread messages as read successfully.// The values of the `unreadCount` attribute of all the one-to-one conversations are set to `0`.}).catch(function(imError) {// Failed to set the unread messages as readconsole.warn('setAllMessageRead error:', imError);});
// Set the unread messages of all the group conversations as readlet promise = chat.setAllMessageRead({scope: TencentCloudChat.TYPES.READ_ALL_GROUP_MSG});promise.then(function(imResponse) {// Set the unread messages as read successfully.// The values of the `unreadCount` attribute of all the group conversations are set to `0`.}).catch(function(imError) {// Failed to set the unread messages as readconsole.warn('setAllMessageRead error:', imError);});
unreadCount
attribute of the Conversation
object indicates the unread message count of a conversation.
If you want to send messages that will not be included in the unread count, such as tips or control messages, you can refer to the following code sample.// The message control option is supported by v2.16.0 or later.chat.sendMessage(message, {messageControlInfo: {// `unreadCount` of the conversation is not updated (the message is stored on the roaming server).excludedFromUnreadCount: true,// `lastMessage` of the conversation is not updated (the message is stored on the roaming server).excludedFromLastMessage: true}});
Was this page helpful?