Chat / Flutter
Current version: v3
Chat Flutter v3
Chat Flutter
Chat
Flutter
Home
/
Chat
/
Flutter
/
Message

Retrieve number of members who haven't read a message

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.
groupChannel.markAsRead();

// 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.

    @override
    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.
                }
            });
        }
    }
}