Chat / iOS
Chat iOS v4
Chat iOS
Chat
iOS
Home
/
Chat
/
iOS
/
Message
This is the new Docs for Chat SDK v4 for iOS. To see the previous Docs, click here.

Retrieve number of members who haven’t read a message

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