/ SDKs / JavaScript
SDKs
Chat SDKs JavaScript v4
Chat SDKs JavaScript
Chat SDKs
JavaScript
Version 4

Mark messages as unread

Copy link

Marking messages as unread allows users to flag messages for later review or to keep track of messages that they haven't read yet. This status change is only visible to the user who marked the message as unread, and it doesn't affect other users in the channel.

This document explains how to mark messages as unread in a group channel.


Read status and unread message count

Copy link

To mark messages as unread, call the markAsUnread() method on the GroupChannel object. You must specify a message that you want to mark as unread. This will be the starting point for the unread status. Messages after this are also treated as unread. Once marked, the SDK updates the unread message count of the group channel and triggers the onUserMarkedUnread() methods in the GroupChannelHandler and onTotalUnreadMessageCountChanged() methods in the UserEventHandler.

JavaScriptTypeScript
await channel.markAsUnread(message);

//...

const channelHandler = new GroupChannelHandler({
    onUserMarkedUnread: (channel, userIds) => {

    },
});
sb.groupChannel.addGroupChannelHandler(UNIQUE_HANDLER_ID, channelHandler);

const userEventHandler = new UserEventHandler({
    onTotalUnreadMessageCountChanged: (unreadMessageCount) => {
        // ...
    },
})
sb.addUserEventHandler(UNIQUE_HANDLER_ID, userEventHandler);

List of parameters

Copy link
Parameter nameTypeDescription

message

BaseMessage

The message that should be the starting point for the unread status. Messages after this will also be treated as unread.