Get unread count
Retrieve unread message counts for community channels and subchannels.
Get the total unread count for all community channels
TypeScript
import { CommunityChannel } from '@nexconn/chat';
const { code, data: totalUnread } = await CommunityChannel.getTotalUnreadCount();
if (code === 0) {
console.log('Total community unread:', totalUnread);
}
Get unread count for a specific community channel
TypeScript
const community = new CommunityChannel('<communityId>');
const { code, data: unread } = await community.getUnreadCount();
if (code === 0) {
console.log('Unread count:', unread);
}
Get unread count for a specific subchannel
TypeScript
import { CommunitySubChannel } from '@nexconn/chat';
const channel = new CommunitySubChannel('<communityId>', '<subChannelId>');
const { code, data: reloadedChannel } = await channel.reload();
if (code === 0 && reloadedChannel) {
console.log('Subchannel unread:', reloadedChannel.unreadCount);
}
tip
Clear the unread count when the user opens a subchannel to mark messages as read. See Sync read status.