/ SDKs / Android
SDKs
Chat SDKs Android v4
Chat SDKs Android
Chat SDKs
Android
Version 4

Retrieve number of members who haven't read a message

Copy link

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 first be updated through markAsRead() before calling the getUnreadMemberCount() method.

// Call markAsRead() when the current user views unread messages in a group channel.
groupChannel.markAsRead(null)
// ...

// To listen to an update from other channel members' client apps, implement onReadReceiptUpdated() with actions to perform when notified.
SendbirdChat.addChannelHandler(
    UNIQUE_HANDLER_ID,
    object : GroupChannelHandler() {
        override fun onReadStatusUpdated(channel: GroupChannel) {
            if (currentGroupChannel.url == channel.url) {
                messages.forEach { message ->
                    val unreadCount = channel.getUnreadMemberCount(message)
                    if (unreadCount <= 0) {
                        // All members have read the message.
                    } else {
                        // Some members haven't read the message yet.
                    }
                }
            }
        }
    }
)