Conversation Unread Count
- Clearing browser cache may cause inaccurate unread message counts.
- 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.
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)
})
Parameter | Type | Required | Description |
---|---|---|---|
includeMuted | Boolean | No | Whether to include muted conversations. Default is false . |
conversationTypes | Array | No | Conversation types. Refer to ConversationType. |
Get Total Unread Mention Count for All Group Conversations
Retrieve the total unread mention count for all group conversation types.
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)
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)
})
Parameter | Type | Required | Description |
---|---|---|---|
conversationTypes | ConversationType[] | Yes | Conversation types. Refer to ConversationType. Chatrooms are not supported. |
levels | NotificationLevel[] | Yes | Do 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)
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)
})
Parameter | Type | Required | Description |
---|---|---|---|
conversationTypes | ConversationType[] | Yes | Conversation types. Refer to ConversationType. Chatrooms are not supported. |
levels | NotificationLevel[] | Yes | Do 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)
})
Parameter | Type | Required | Description |
---|---|---|---|
targetId | String | Yes | The userId of the recipient. |
conversationType | Number | Yes | Conversation 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)
}
})
Parameter | Type | Required | Description |
---|---|---|---|
targetId | String | Yes | The userId of the recipient. |
conversationType | Number | Yes | Conversation type. Refer to ConversationType. |
Clear Unread Count for All Conversations
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(() => {})
}
})