Chat / JavaScript
Chat JavaScript v4
Chat JavaScript
Chat
JavaScript
Home
/
Chat
/
JavaScript
/
Message
This is the new Docs for Chat SDK v4 for JavaScript. To see the previous Docs, click here.

Retrieve number of members who haven't read a message

By using the getUnreadMemberCount() method, you can get the number of members who haven't read a specific message in a group channel. To get the most up-to-date value, the channel should be updated first through markAsRead() before calling the getUnreadMemberCount() method.

const count: number = channel.getUnreadMemberCount();
// ...

// To listen to an update from all client apps of channel members, implement the onReadReceiptUpdated() method with following behaviors to perform when notified.
const channelHandler = new GroupChannelHandler({
    onUnreadMemberCountUpdated: (channel: GroupChannel) => {
        //...
        for (const message of messages) {
            const unreadCount: number = channel.getUnreadMemberCount(message);
            if (unreadCount <= 0) {
            // All members have read the message.
            } else {
            // Some of members haven't read the message yet.
            }
        }
    },
});
sb.groupChannel.addGroupChannelHandler(UNIQUE_HANDLER_ID, channelHandler);