Get unread messages
Retrieve unread messages from a community subchannel.
info
The getUnreadMessages() method is not available in the current client SDK version.
To retrieve recent messages for a subchannel, use BaseChannel.createMessagesQuery and compare against the last read timestamp to identify unread messages.
Get remote messages (workaround)
TypeScript
import { CommunitySubChannel, BaseChannel } from '@nexconn/chat';
const channel = new CommunitySubChannel('<communityId>', '<subChannelId>');
// Retrieve recent messages from the server
const query = BaseChannel.createMessagesQuery({
channelIdentifier: channel.identifier,
startTime: Date.now(),
pageSize: 20,
isAscending: false,
});
const { code, data: messages } = await query.loadNextPage();
if (code === 0) {
console.log('Recent messages:', messages);
}
Get unread count
To get the number of unread messages without fetching their content:
TypeScript
await channel.reload();
console.log('Unread count:', channel.unreadCount);
Clear unread count
After the user reads messages, clear the unread count:
TypeScript
const { code } = await channel.clearUnreadCount();
if (code === 0) {
console.log('Unread count cleared');
}