// Get the ID of the oldest message on the current page
const lastMessageId = messages[0].id;
// Fetch older messages
const result = await channel.query({
messages: { limit: 20, id_lt: lastMessageId },
});
// Fetch messages around a specific message
const result = await channel.query({
messages: { limit: 20, id_around: messageId },
});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
| Parameter | Description |
|---|---|
id_lt | Retrieve messages older than (less than) the ID |
id_gt | Retrieve messages newer than (greater than) the ID |
id_lte | Retrieve messages older than or equal to the ID |
id_gte | Retrieve messages newer than or equal to the ID |
id_around | Retrieve messages around a specific message ID |
// Channel is loaded with the most recent messages
var channel = await Client.GetOrCreateChannelWithIdAsync(ChannelType.Messaging, channelId: "my-channel-id");
// Every call will load 1 more page of messages
await channel.LoadOlderMessagesAsync();Member and Watcher Pagination
Members and watchers use limit and offset parameters for pagination.
| Parameter | Description | Maximum |
|---|---|---|
limit | Number of records to return | 300 |
offset | Number of records to skip | 10000 |
var channel = await Client.GetOrCreateChannelWithIdAsync(ChannelType.Messaging, channelId: "my-channel-id");
// channel.Members exposes the loaded members snapshot (max 100 by default)
foreach (var member in channel.Members)
{
// ...
}
// channel.Watchers exposes the loaded watchers snapshot (max 100 by default)
foreach (var watcher in channel.Watchers)
{
// ...
}
// Use QueryMembersAsync to page beyond the loaded snapshot
var filters = new Dictionary<string, object>();
var nextMembers = await channel.QueryMembersAsync(filters, limit: 20, offset: 0);
// Paginating watchers beyond the loaded list is not yet available in the Unity SDK.
// Please let us know if you'd like this feature implemented: https://github.com/GetStream/stream-chat-unity/issuesTo retrieve filtered and sorted members in a channel use the Query Members API