/ SDKs / iOS
SDKs
Chat SDKs iOS v4
Chat SDKs iOS
Chat SDKs
iOS
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 channelDidUpdateReadStatus(_:) delegate method in the GroupChannelDelegate and didUpdateTotalUnreadMessageCount(unreadMessageCount:) delegate method in the UserEventDelegate.

In the meantime, the channelDidUpdateReadStatus(_:) delegate method of GroupChannelDelegate can also be implemented to listen to read status updates by other channel members.

groupChannel.markAsUnread(message) { error in 
  // Handle error if any.
}

// Listen to updates in the current user's `myLastRead` of the channel through the method below.
// Also use this to listen to a read status update by other channel members.
func channelDidUpdateReadStatus(_ channel: BaseChannel, userIds: [String]) {
    // ...
}

// Listen to updates in the current user's unread message count through the method below.
func didUpdateTotalUnreadMessageCount(unreadMessageCount:) {
    let totalUnreadCount = unreadMessageCount.groupChannelCount 
}

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.

completionHandler

SBErrorHandler?

The completion handler that passes an optional SBError.