会话未读数
危险
- 会话消息未读数存储在 localStorage 中, 若浏览器不支持或禁用 localStorage,未读消息数将不会保存,浏览器页面刷新未读消息数将不会存在
- 清除浏览器缓存会导致会话未读数不准确。
获取所有会话未读数
调用 getTotalUnreadCount 方法,获取所有会话类型的未读数。
接口
JavaScript
getTotalUnreadCount(includeMuted, conversationTypes)
参数说明
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| includeMuted | boolean | 否 | 是否包含免打扰会话,默认为 false |
| conversationTypes | ConversationType[] | 否 | 会话类型,不支持聊天室、超级群会话 |
示例代码
JavaScript
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)
})
获取所有群会话未读 @ 消息数
提示
- 仅支持普通群会话
- SDK 从 5.9.0 版本开始支持该接口
调用 getAllUnreadMentionedCount 方法,获取所有会话类型的未读 @ 消息数。
接口
JavaScript
RongIMLib.getAllUnreadMentionedCount()
参数说明
无
示例代码
JavaScript
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)
})