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

Retrieve number of members who haven't read a message

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.
                    }
                }
            }
        }
    }
)