Files
stream-chat-flutter/docusaurus/docs/Flutter/stream_chat/paginating_channels.mdx
T
2021-06-17 14:22:50 +05:30

35 lines
1.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
id: paginating_channels
sidebar_position: 15
title: Channel Pagination
---
The channel query endpoint allows you to paginate the list of messages, watchers, and members for one channel.
To make sure that you are able to retrieve a consistent list of messages, pagination does not work with simple offset/limit parameters but instead,
it relies on passing the ID of the messages from the previous page.
For example: say that you fetched the first 100 messages from a channel and want to lead the next 100.
To do this you need to make a channel query request and pass the ID of the oldest message if you are paginating in descending order or the ID of the newest message if paginating in ascending order.
Use the `id_lt` parameter to retrieve messages older than the provided ID and `id_gt` to retrieve messages newer than the provided ID.
The terms `id_lt` and `id_gt` stand for ID less than and ID greater than.
ID-based pagination improves performance and prevents issues related to the list of messages changing while youre paginating. If needed, you can also use the inclusive versions of those two parameters: id_lte and id_gte.
```dart
final response = await channel.query(
messagesPagination: PaginationParams(limit: 2, lessThanOrEqual: "123"),
membersPagination: PaginationParams(limit: 2, offset: 0),
watchersPagination: PaginationParams(limit: 2, offset: 0),
);
```
For members and watchers, we use limit and offset parameters.
<b>Notes:</b>
1. Soon we will create friendlier aliases for `id_lt` and `id_gt`. Our best candidates are before_id and after_id,
let us know if you have any feedback or suggestion!
2. The maximum number of messages that can be retrieved at once from the API is 300.