Channels

When you retrieve a channel from the API (e.g. using query channels), the read state for all members is included in the response. This allows you to display which messages are read by each user. For each member, we include the last time he or she marked the channel as read.

let channelController = client.channelController(for: .init(type: .messaging, id: "general"))
    
channelController.synchronize() { error in
  if error == nil {
    channelController.channel?.reads
  }
}

Unread Messages Per Channel

You can retrieve the count of unread messages for the current user on a channel like this:

let channelController = client.channelController(for: .init(type: .messaging, id: "general"))

class ChannelDelegate: ChatChannelControllerDelegate {
  func channelController(_ channelController: ChatChannelController,
              didUpdateChannel channel: EntityChange<ChatChannel>) {
    channelController.channel?.unreadCount
  }
}

channelController.delegate = ChannelDelegate()

channelController.synchronize()

Unread Mentions Per Channel

You can retrieve the count of unread messages mentioning the current user on a channel like this:

let channelController = client.channelController(for: .init(type: .messaging, id: "general"))

class ChannelDelegate: ChatChannelControllerDelegate {
  func channelController(_ channelController: ChatChannelController,
              didUpdateChannel channel: EntityChange<ChatChannel>) {
    channelController.channel?.unreadCount.mentionedMessages
  }
}

channelController.delegate = ChannelDelegate()

channelController.synchronize()

Mark All As Read

You can mark all channels as read for a user like this:

let channelListController = client.channelListController(query: .init(filter: .containMembers(userIds: ["joe"])))
channelListController.markAllRead()
© Getstream.io, Inc. All Rights Reserved.