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.

// Get channel
val queryChannelRequest = QueryChannelRequest().withState()

client.queryChannel(
  channelType = "channel-type",
  channelId = "channel-id",
  request = queryChannelRequest,
).enqueue { result ->
  if (result.isSuccess) {
    // readState is the list of read states for each user on the channel
    val readState: List<ChannelUserRead> = result.data().read
  } else {
    // Handle result.error()
  }
}

Unread Messages Per Channel

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

// Get channel
val queryChannelRequest = QueryChannelRequest().withState()

client.queryChannel(
  channelType = "channel-type",
  channelId = "channel-id",
  request = queryChannelRequest,
).enqueue { result ->
  if (result.isSuccess) {
    // Unread count for current user
    val unreadCount = result.data().unreadCount
  } else {
    // Handle result.error()
  }
}

Unread Mentions Per Channel

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

// Get channel
val queryChannelRequest = QueryChannelRequest().withState()
val currentUser = client.getCurrentUser()
if (currentUser == null) {
  // Handle user not connected state
  return
}

client.queryChannel(
  channelType = "channel-type",
  channelId = "channel-id",
  request = queryChannelRequest,
).enqueue { result ->
  if (result.isSuccess) {
    // Unread mentions
    val channel = result.data()
    val unreadCount = channel.countUnreadMentionsForUser(currentUser)
  } else {
    // Handle result.error()
  }
}

Mark All As Read

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

client.markAllRead().enqueue { result ->
  if (result.isSuccess) {
    //Handle success
  } else {
    //Handle failure
  }
}
© Getstream.io, Inc. All Rights Reserved.