Files
stream-chat-flutter/docusaurus/docs/Flutter/stream_chat/querying_channels.mdx
T
2021-06-15 21:40:14 +05:30

39 lines
1.4 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: querying_channels
sidebar_position: 7
title: Querying Channels
---
If youre building a similar application to Facebook Messenger or Intercom, youll want to show a list of Channels.
The Chat API supports MongoDB style queries to make this easy to implement.
You can query channels based on built-in fields as well as any custom field you add to channels.
Multiple filters can be combined using AND, OR logical operators, each filter can use its comparison (equality, inequality, greater than, greater or equal, etc.). You can find the complete list of supported operators in the query syntax section of the docs.
As an example, let's say that you want to query the last conversations I participated in sorted by `last_message_at`.
Heres an example of how you can query the list of channels:
```dart
final filter = Filter.in_('members', ['thierry']);
final sort = [SortOption("last_message_at", direction: SortOption.DESC)];
final channels = await client.queryChannels(
filter: filter,
sort: sort,
options: {
"watch": true,
"state": true,
},
);
channels.forEach((Channel c) {
print("${c.extraData['name']} ${c.cid}");
});
```
The query channels endpoint will only return channels that the user can read,
you should make sure that the query uses a filter that includes such logic.
For example: messaging channels are readable only to their members,
such requirement can be included in the query filter (see below).