Skip to main content

Conversation Unread Count

danger
  1. Clearing browser cache may cause inaccurate unread message counts.
  2. Unread message counts are stored in localStorage. If the browser does not support or has disabled localStorage, unread message counts will not be saved, and refreshing the browser page will result in the loss of unread message counts.

Get Total Unread Count for All Conversations

Retrieve the total unread message count for all conversation types.

tip

Chatroom and ultra group conversations are not supported.

API Reference: getTotalUnreadCount

const includeMuted = false
const conversationTypes = [RongIMLib.ConversationType.PRIVATE, RongIMLib.ConversationType.GROUP]
RongIMLib.getTotalUnreadCount(includeMuted, conversationTypes).then(res => {
if (res.code === 0) {
console.log(res.code, res.data)
} else {
console.log(res.code, res.msg)
}
}).catch(error => {
console.log(error)
})
ParameterTypeRequiredDescription
includeMutedBooleanNoWhether to include muted conversations. Default is false.
conversationTypesArrayNoConversation types. Refer to ConversationType.

Get Total Unread Mention Count for All Group Conversations

Retrieve the total unread mention count for all group conversation types.

tip

Only regular group conversations are supported. This API is supported starting from SDK version 5.9.0.

API Reference: getAllUnreadMentionedCount

RongIMLib.getAllUnreadMentionedCount().then(res => {
if (res.code === 0) {
console.log(res.code, res.data)
} else {
console.log(res.code, res.msg)
}
}).catch(error => {
console.log(error)
})

Get Unread Count by Do Not Disturb Level (Web Only)

tip

This API is supported starting from SDK version 5.5.1 and is not available on the Electron platform.

Retrieve the total unread message count for conversations that match the specified Do Not Disturb levels.

API Reference: getTotalUnreadCountByLevels

const conversationTypes = [
RongIMLib.ConversationType.PRIVATE,
RongIMLib.ConversationType.GROUP,
RongIMLib.ConversationType.ULTRA_GROUP,
]
const levels = [
RongIMLib.NotificationLevel.AT_MESSAGE_NOTIFICATION,
RongIMLib.NotificationLevel.AT_USER_NOTIFICATION
]
RongIMLib.getTotalUnreadCountByLevels(conversationTypes, levels).then(res => {
if (res.code === 0) {
console.log(res.data)
} else {
console.log(res.msg)
}
}).catch(error => {
console.log(error)
})
ParameterTypeRequiredDescription
conversationTypesConversationType[]YesConversation types. Refer to ConversationType. Chatrooms are not supported.
levelsNotificationLevel[]YesDo Not Disturb levels. The SDK will match conversations based on these levels and calculate the unread message count. Refer to NotificationLevel. If an empty array is passed, the total unread count for all Do Not Disturb levels will be calculated.

Get Unread Mention Count by Do Not Disturb Level (Web Only)

tip

This API is supported starting from SDK version 5.5.1 and is not available on the Electron platform.

Retrieve the total unread mention count for conversations that match the specified Do Not Disturb levels.

API Reference: getTotalUnreadMentionedCountByLevels

const conversationTypes = [
RongIMLib.ConversationType.PRIVATE,
RongIMLib.ConversationType.GROUP,
RongIMLib.ConversationType.ULTRA_GROUP,
]
const levels = [
RongIMLib.NotificationLevel.AT_MESSAGE_NOTIFICATION,
RongIMLib.NotificationLevel.AT_USER_NOTIFICATION
]
RongIMLib.getTotalUnreadMentionedCountByLevels(conversationTypes, levels).then(res => {
if (res.code === 0) {
console.log(res.data)
} else {
console.log(res.msg)
}
}).catch(error => {
console.log(error)
})
ParameterTypeRequiredDescription
conversationTypesConversationType[]YesConversation types. Refer to ConversationType. Chatrooms are not supported.
levelsNotificationLevel[]YesDo Not Disturb levels. The SDK will match conversations based on these levels and calculate the unread mention count. Refer to NotificationLevel. If an empty array is passed, the total unread mention count for all Do Not Disturb levels will be calculated.

Get Unread Count for a Specific Conversation

API Reference: getUnreadCount

const conversationType = RongIMLib.ConversationType.PRIVATE;
const targetId = "Conversation ID";

RongIMLib.getUnreadCount({ conversationType, targetId }).then(res => {
if (res.code === 0) {
console.log(res.code, res.data)
} else {
console.log(res.code, res.msg)
}
}).catch(error => {
console.log(error)
})
ParameterTypeRequiredDescription
targetIdStringYesThe userId of the recipient.
conversationTypeNumberYesConversation type. Refer to ConversationType.

Clear Unread Count for a Specific Conversation

Clear the unread count for a specific conversation (excluding chatrooms).

API Reference: clearMessagesUnreadStatus

const conversationType = RongIMLib.ConversationType.PRIVATE;
const targetId = "Conversation ID";

RongIMLib.clearMessagesUnreadStatus({ conversationType, targetId }).then(res => {
if (res.code === 0) {
console.log(res.code)
} else {
console.log(res.code, res.msg)
}
})
ParameterTypeRequiredDescription
targetIdStringYesThe userId of the recipient.
conversationTypeNumberYesConversation type. Refer to ConversationType.

Clear Unread Count for All Conversations

tip

Minimum SDK version: 5.0.2

RongIMLib.clearAllMessagesUnreadStatus()

Multi-Device Unread Count Synchronization

Unread messages are stored in localStorage, and the unread count is specific to the current device. The server does not store unread message counts.

API Reference: sendSyncReadStatusMessage

// Clear unread count
const conversationType = RongIMLib.ConversationType.PRIVATE;
const targetId = "Conversation ID";

RongIMLib.clearMessagesUnreadStatus({ conversationType, targetId }).then(res => {
if (res.code === 0) {
// Clear successful
console.log(res)
// Send multi-device unread count synchronization message
RongIMLib.sendSyncReadStatusMessage({ conversationType, targetId }, Date.now()).then(() => {})
}
})