/ SDKs / iOS
SDKs
Chat SDKs iOS v4
Chat SDKs iOS
Chat SDKs
iOS
Version 4

Mark messages as read

Copy link

In a group channel, the read status of messages is crucial for understanding which messages have been read by which members. This document explains how to mark messages as read in a group channel.

To keep the most up-to-date and accurate read status of messages for all group channel members, call the markAsRead(completionHandler:) method in the following cases:

  • When a channel member enters the channel and reads messages.
  • When a channel member switches the chat view from the background to the foreground.

Read receipts

Copy link

Message sender

Copy link

When a member sends a message in a group channel, the Sendbird server automatically updates the sender's read receipt to the time when the message was sent. This ensures that the sender's read status reflects their own action of sending the message.

Other channel members

Copy link

When other member reads messages in a group channel, the Sendbird server updates the read receipt of that member to the time when they read the messages. This is done by calling the markAsRead(completionHandler:) method.


Unread message count

Copy link

If a member enters the channel and the markAsReadAll(completionHandler:) is called, the Sendbird server updates the following:

  • The unread message count of the individual channel.
  • The total unread message count of all the group channels joined by the member.

The server then triggers the channelDidUpdateReadStatus(_:) method of the channel event delegate to notify the change of read status to all other channel members' devices.

// Call the markAsRead method when the current user views
// unread messages in a group channel.
channel.markAsRead { error in
    guard error == nil else {
        // Handle error.
        return
    }
}


// To listen to an update from other channel members' client apps,
// implement the `channelDidUpdateReadStatus(_:)` with actions to perform when notified.
class GroupChannelChattingViewController: UIViewController, GroupChannelDelegate {
    func initViewController() {
        SendbirdChat.add(self as GroupChannelDelegate, identifier: UNIQUE_DELEGATE_ID)
    }

    func channelDidUpdateReadStatus(_ channel: GroupChannel) {
        if currentGroupChannel.channelURL == channel.channelURL {
            // You can implement codes to redraw a channel view here.
        }
    }
}

Display past messages for new members

Copy link

If a new member joins the channel, the channelDidUpdateReadStatus(_:) method works differently based on the value of the display_past_message property of your Sendbird application. The display_past_message property determines whether to display past messages to newly joined members when they enter the channel.

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.

Note: This property is also linked to the Chat history option, which can be managed on Sendbird Dashboard under Settings > Chat > Channels > Group channels.