feat: Added new docs
This commit is contained in:
@@ -4,3 +4,67 @@ sidebar_position: 4
|
||||
title: Querying Users
|
||||
---
|
||||
|
||||
The Query Users method allows you to search for users and see if they are online/offline.
|
||||
The example below shows how you can retrieve the details for 3 users in one API call:
|
||||
|
||||
```dart
|
||||
final _result = client.queryUsers(
|
||||
filter: Filter.in_('id', ['john', 'jack', 'jessie']),
|
||||
);
|
||||
```
|
||||
|
||||
You can also add sort options and pagination to the query:
|
||||
|
||||
```dart
|
||||
final _result = client.queryUsers(
|
||||
filter: Filter.in_('id', ['john', 'jack', 'jessie']),
|
||||
sort: [SortOption('last_active')],
|
||||
pagination: PaginationParams(
|
||||
offset: 0,
|
||||
limit: 20,
|
||||
),
|
||||
);
|
||||
```
|
||||
|
||||
You can filter and sort on the custom fields you've set for your user, the user id, and when the user was last active.
|
||||
|
||||
The options for the queryUser method are presence, limit, and offset.
|
||||
If presence is true this makes sure you receive the user.presence.changed event when a user goes online or offline.
|
||||
|
||||
### Querying using the autocomplete operator
|
||||
|
||||
You can autocomplete the results of your user query by username and/or ID.
|
||||
|
||||
### By Custom Field
|
||||
|
||||
```dart
|
||||
final _result = client.queryUsers(
|
||||
filter: Filter.autoComplete('name', 'ro'),
|
||||
);
|
||||
```
|
||||
This would return an array of any matching users, such as:
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"id": "userID",
|
||||
"name": "Curiosity Rover"
|
||||
},
|
||||
{
|
||||
"id": "userID2",
|
||||
"name": "Roxy"
|
||||
},
|
||||
{
|
||||
"id": "userID3",
|
||||
"name": "Roxanne"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
### By ID
|
||||
|
||||
```dart
|
||||
final _result = client.queryUsers(
|
||||
filter: Filter.autoComplete('id', 'USER_ID'),
|
||||
);
|
||||
```
|
||||
@@ -4,3 +4,89 @@ sidebar_position: 5
|
||||
title: User Presence
|
||||
---
|
||||
|
||||
User presence allows you to show when a user was last active and if they are online right now.
|
||||
Whenever you read a user the data will look like this:
|
||||
|
||||
```json
|
||||
{
|
||||
id: 'unique_user_id',
|
||||
online: true,
|
||||
status: 'Eating a veggie burger...',
|
||||
last_active: '2019-01-07T13:17:42.375Z'
|
||||
}
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
||||
1. The online field indicates if the user is online. The status field stores text indicating the current user status.
|
||||
2. The last_active field is updated when a user connects and then refreshed every 15 minutes.
|
||||
|
||||
### Invisible
|
||||
|
||||
To mark a user invisible simply set the invisible property to true. You can also set a custom status message at the same time:
|
||||
|
||||
```dart
|
||||
await client.connectUser(
|
||||
User(
|
||||
id: 'super-band-9',
|
||||
extraData: {
|
||||
'invisible': true,
|
||||
},
|
||||
),
|
||||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoic3VwZXItYmFuZC05In0.0L6lGoeLwkz0aZRUcpZKsvaXtNEDHBcezVTZ0oPq40A',
|
||||
);
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
||||
1. When invisible is set to true, the current user will appear as offline to other users.
|
||||
|
||||
### Listening to Presence Changes
|
||||
|
||||
Of course, you want to listen to the user presence changes. This allows you to show a user as offline when they leave and update their status in real time.
|
||||
These 3 endpoints allow you to watch user presence:
|
||||
|
||||
```dart
|
||||
// If you pass presence: true to channel.watch it will watch the list of user presence changes.
|
||||
// Note that you can listen to at most 10 users using this API call
|
||||
final channel = client.channel(
|
||||
'messaging',
|
||||
id: 'flutterdevs',
|
||||
extraData: {
|
||||
'name': 'Flutter devs',
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
await channel.watch({
|
||||
'presence': true,
|
||||
});
|
||||
|
||||
// queryChannels allows you to listen to the members of the channels that are returned
|
||||
// so this does the same thing as above and listens to online status changes for john and jack
|
||||
|
||||
final filter = Filter.in_('members', ['john']);
|
||||
|
||||
final sort = [SortOption("last_message_at", direction: SortOption.DESC)];
|
||||
|
||||
final channels = await client.queryChannels(
|
||||
filter: filter,
|
||||
sort: sort,
|
||||
options: {
|
||||
'presence': true,
|
||||
},
|
||||
);
|
||||
|
||||
// queryUsers allows you to listen to user presence changes for john and jack
|
||||
final result = await client.queryUsers(
|
||||
filter: Filter.in_('id', ['john', 'jack', 'jessie']),
|
||||
sort: [SortOption('last_active')],
|
||||
pagination: PaginationParams(
|
||||
offset: 0,
|
||||
limit: 20,
|
||||
),
|
||||
options: {
|
||||
'presence': true,
|
||||
},
|
||||
);
|
||||
```
|
||||
Reference in New Issue
Block a user