Channel Pagination

The channel query endpoint allows you to paginate messages, watchers, and members for a channel. Messages use ID-based pagination for consistency, while members and watchers use offset-based pagination.

Message Pagination

Message pagination uses ID-based parameters rather than simple offset/limit. This approach improves performance and prevents issues when the message list changes while paginating.

For example, if you fetched the first 100 messages and want to load the next 100, pass the ID of the oldest message (when paginating in descending order) or the newest message (when paginating in ascending order).

Pagination Parameters

ParameterDescription
id_ltRetrieve messages older than (less than) the ID
id_gtRetrieve messages newer than (greater than) the ID
id_lteRetrieve messages older than or equal to the ID
id_gteRetrieve messages newer than or equal to the ID
id_aroundRetrieve messages around a specific message ID
val channelClient = client.channel("messaging", "general")
val pageSize = 10

// Request the first page
val request = QueryChannelRequest()
  .withMessages(pageSize)

channelClient.query(request).enqueue { result ->
  if (result is Result.Success) {
    val messages: List<Message> = result.value.messages
    if (messages.size < pageSize) {
      // All messages loaded
    } else {
      // Load next page using the oldest message ID
      val nextRequest = QueryChannelRequest()
        .withMessages(Pagination.LESS_THAN, messages.last().id, pageSize)
      // ...
    }
  } else {
    // Handle Result.Failure
  }
}

Member and Watcher Pagination

Members and watchers use limit and offset parameters for pagination.

ParameterDescriptionMaximum
limitNumber of records to return300
offsetNumber of records to skip10000
// Paginate members and watchers
const result = await channel.query({
  members: { limit: 20, offset: 0 },
  watchers: { limit: 20, offset: 0 },
});

const result = await channel.query({
  state: true,
  members: { limit: 110, offset: 0 },
});

To retrieve filtered and sorted members in a channel use the Query Members API