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

Retrieve number of members who haven’t read a message

Copy link

By using the getUnreadMemberCount(_:) 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 be updated first through markAsRead(completionHandler:) before calling the getUnreadMemberCount(_:) method.

// 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(_:) function
// 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 {
            for msg in messages {
                let unreadCount = channel.getUnreadMemberCount(msg)
                if unreadCount <= 0 {
                    // All members have read the message.
                }
                else {
                    // Some of members haven't read the message.
                }
            }
        }
    }
}