logo
On this page

Manage unread message counts


Introduction

Through ZIM, you can get the unread message count for an individual conversation, acquire the total unread message count for all conversations, and clear the aforementioned values.

Get the unread message count of one conversation

ZIM supports actively or passively obtaining the number of unread messages of a conversation.

Actively obtaining

To actively obtain the number of unread messages in a conversation, first call queryConversationList or queryConversation to obtain the target conversation object. Then, you can use the unreadMessageCount property of the target conversation object to know the number of unread messages in that conversation.

Passively obtaining

Listen for the conversationChanged callback to obtain the unreadMessageCount property of a conversation and know the latest number of unread messages in that conversation. For more details, refer to Get conversation list - Listen for conversation changes.

Get the total unread message count of all conversations

To know how many unread messages you currently have after login, listen for the callback conversationTotalUnreadMessageCountUpdated of theon method.

After a successful login, the client user is notified of the update of the total number of unread messages through the callback in any of the following situations:

  • The user receives a new message and the message notification is enabled for the current conversation.
  • The user proactively clears the number of unread conversation messages. For details, see the chapter above Clear the number of unread conversation messages.

With this callback, you can adjust your app's UI display to remind the client user how many messages are currently unread.

Untitled
zim.on('conversationTotalUnreadMessageCountUpdated', function(zim, { totalUnreadMessageCount }){
    // Obtain the total number of unread messages of all conversations and display it on the UI.
})
1
Copied!

Clear the unread message count of one conversation

To clear the unread message number of one conversation after getting the conversation list, call the clearConversationUnreadMessageCount method.

Because the ZIM SDK does not know when your app users should clear the unread count of the conversation, you need to call this method when your app users interact with specific pages. The following are some common scenarios to call this method:

  • Users click a conversation to enter the chat interface.
  • Users stay in the same conversation, and this method should be called every time the user receiving a new message.
  • Users mark a specified conversation as read in the conversation list interface.
titile="Sample
var conversationID = '';
var conversationType = 0;
zim.clearConversationUnreadMessageCount(conversationID, conversationType)
    .then(function(res){
        // Operation succeeded.
    })
    .catch(function(err){
        // Operation failed.
    })
1
Copied!

Clear the total unread message count of all conversations

To clear the unread message numbers of all conversations after getting the conversation list, call the clearConversationTotalUnreadMessageCount method.

When you want to clear the unread message counts of all conversations and total unread conversation count, you can use this interface.

Untitled
// Clear the unread message counts of all conversations
zim.clearConversationTotalUnreadMessageCount()
    .then(function(){
        // Operation succeeded
    })
    .catch(function(err){
        // Operation failed
    })
1
Copied!

Previous

Get the conversion list

Next

Mute a conversation