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

Mark messages as unread

Copy link

Marking messages as unread allows users to flag messages for later review or to keep track of messages that they haven't read yet. This status change is only visible to the user who marked the message as unread, and it doesn't affect other users in the channel.

This document explains how to mark messages as unread in a group channel.


Read status and unread message count

Copy link

To mark messages as unread, call the markAsUnread() method on the GroupChannel object. You must specify a message that you want to mark as unread. This will be the starting point for the unread status. Messages after this are also treated as unread. Once marked, the SDK updates the unread message count of the group channel and triggers the onChannelChanged() methods in the GroupChannelHandler.

To listen to the changes in the read status by other channel members, add a user event handler to the SendbirdChat instance and define the onTotalUnreadMessageCountChanged() method with the actions to perform when notified.

groupChannel.markAsUnread(message, null)

SendbirdChat.addChannelHandler(
    UNIQUE_CHANNEL_HANDLER_ID,
    object : GroupChannelHandler() {
        override fun onChannelChanged(channel: BaseChannel) {
            // ..
        }

        // To listen to an update from other channel members' read status,
        // define onReadStatusUpdated() with actions to perform when notified.
        override fun onReadStatusUpdated(channel: GroupChannel) {
            if (currentGroupChannel.url == channel.url) {
                // For example, you can redraw a channel view here.
            }
            
            // ...
        }
    }
)

SendbirdChat.addUserEventHandler(
    UNIQUE_USER_EVENT_HANDLER_ID,
    object : UserEventHandler() {
        override fun onTotalUnreadMessageCountChanged(unreadMessageCount: UnreadMessageCount) {
            // ...
        }
    }
)

List of parameters

Copy link
Parameter nameTypeDescription

message

BaseMessage

The message that should be the starting point for the unread status. Messages after this will also be treated as unread.