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

Mark messages as read

Copy link

To keep the most up-to-date and accurate read status of messages for all group channel members, the markAsRead() method should be called every time a member reads messages by entering the channel from a channel list or switching the chat view from the background to the foreground.

When a channel member sends a message to the channel, the Sendbird server immediately updates the sender's read receipt to the time when the message was sent. The read receipts of other channel members are updated when the markAsRead() method is called.

If a member opens a channel and the markAsReadAll() method is called, the Sendbird server updates both the unread message count of the individual channel and the total unread message count of all the group channels joined by the member. The server then triggers the onReadStatusUpdated() method of the channel event handler to notify the change of the read status to all other channel members' devices.

If a new member joins the channel, the method works differently based on the value of the display_past_message property of your Sendbird application. If the property is set to true, the new member's read receipt is updated to the sent time of the last message in the channel. If set to false, the property's value is 0.

// 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 onReadStatusUpdated() with actions to perform when notified.
SendbirdChat.addChannelHandler(
    UNIQUE_HANDLER_ID,
    object : GroupChannelHandler() {
        override fun onMessageReceived(channel: BaseChannel, message: BaseMessage) {}

        override fun onReadStatusUpdated(channel: GroupChannel) {
            if (currentGroupChannel.url == channel.url) {
                // For example, you can redraw a channel view here.
            }

            // ...
        }
    }
)

Note: The display_past_message property determines whether to display past messages to newly joined members when they enter the channel. This property is also linked to the Chat history option, which can be managed on Sendbird Dashboard under Settings > Chat > Channels > Group channels.


Mark messages as unread

Copy link

Call the markAsUnread() method to return a message's read status back to unread in a group channel. This is useful when users need to flag messages for later review or when they want 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.

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.


Get read status of a message

Copy link

You can get the read status of all members in the channel through the getReadStatus() method in the Group channel class. If its parameter includeAllMembers is set to false, the result won't contain the read status of the current user.

// If includeAllMembers is false, the result won't include the current user.
val membersReadStatus = groupChannel.getReadStatus(includeAllMembers = true)
membersReadStatus.forEach { userId, status ->
    // Handle the read status of each member.
}