/ SDKs / Flutter
Chat SDKs Flutter v3
Chat SDKs Flutter
Chat SDKs
Version 3
Sendbird Chat SDK v3 for Flutter is no longer supported as a new version is released. Check out our latest Chat SDK v4

Retrieve number of members who haven't read a message

Copy link

Using the getUnreadMembers() 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 getUnreadMembers().

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

// To listen to an update from all the other channel members' client apps, implement onReadReceiptUpdated with actions to do when notified.
class MyClass with ChannelEventHandler {
    // Add this class through sendbird.addChannelEventHandler(UNIQUE_HANDLER_ID, this).
    // Or remove it through sendbird.removeChannelEventHandler(UNIQUE_HANDLER_ID) when it's no longer needed.

    void onReadReceiptUpdated(GroupChannel channel) {
        if (currentGroupChannel.channelUrl == channel.channelUrl) {
            messages.forEach((m) {
                final unreadCount = channel.getUnreadMembers(m);
                if (unreadCount <= 0) {
                    // 0 means that all members have read this message.
                } else {
                    // If the value isn't 0, 
                    // some members haven't read this message.