A user's conversation list usually contains multiple conversations. If there is a new message in one of the conversations, a badge needs to be displayed in the list cell to indicate the unread count.
After the user clicks to enter the conversation and goes back to the conversation list, the unread count is cleared, and the badge disappears. In some applications, the total unread count of all the conversations is calculated and displayed at the bottom tab of the conversation list.
UI Display
Get the total number of unread messages in all conversations
Note:
1. Only applicable to Work/Public/Community/Meeting group. AVChatRoom are not currently supported.
2. The total number of unread messages will subtract the unread count of conversations set to Do Not Disturb.
3. The total number of unread messages does not include the unread count of system conversations.
4. Because this interface relies on the SDK to synchronize the conversation list from the cloud, the total number of unread messages obtained immediately after successful login may be 0. The access side can update the local total number of unread messages in combination with the TencentCloud.EVENT.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED event.
API
chat.getTotalUnreadMessageCount();
Return value
Number
Examples
// The total number of unread messages in one-to-one and group conversations
let totalUnreadCount = chat.getTotalUnreadMessageCount();
Notification of change in total number of unread messages in all conversations
Sending a message excluded from the conversation unread count
In normal cases, both one-to-one messages and group messages that are sent will be included in the unread count. The 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.
Examples
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).