AI Integration Quick Reference
AI Integration Quick Reference
Retrieve List of Groups
In other words, as a logged-in user, how do I retrieve the list of groups I’ve joined and groups that are available? In order to fetch the list of groups, you can use theGroupsRequest class. To use this class i.e to create an object of the GroupsRequest class, you need to use the GroupsRequestBuilder class. The GroupsRequestBuilder class allows you to set the parameters based on which the groups are to be fetched.
Set Limit
This method sets the limit i.e. the number of groups that should be fetched in a single iteration.- Dart
Set Search Keyword
With offline support on, this filter is answered by the server only; the cached page is empty.
- Dart
Joined Only
This method when used, will ask CometChat to only return the groups that the user has joined or is a part of.- Dart
Set Tags
This method accepts a list of tags based on which the list of groups is to be fetched. The list fetched will only contain the groups that have been tagged with the specified tags.- Dart
With Tags
This property when set to true will fetch tags data along with the list of groups.- Dart
build() method to get the object of the GroupsRequest class.
Once you have the object of the GroupsRequest class, you need to call the fetchNext() method. Calling this method will return a list of Group objects containing ‘n’ number of groups depending on the limit set.
The list of groups fetched will only have the public and password type groups. The private groups will only be available if the user is a member of that private group.
Starting with v5.1.0, `fetchNext()` accepts a
listener: parameter. Pass a `GroupFetchListener` to receive the on-device cached result. The listener: parameter requires cometchat_sdk 5.1.0 or later, so on 5.0.x keep using onSuccess/onError. With offline support off, the listener behaves exactly like the callbacks: onError is unchanged, and the server result arrives in the onServer… callback instead of onSuccess. With offline support on, the listener also delivers the cached result first, then the server result. onSuccess/onError keep working and receive only the server result. See Show Cached Data.- Dart
Retrieve Particular Group Details
In other words, as a logged-in user, how do I retrieve information for a specific group? To get the information of a group, you can use thegetGroup() method.
- Dart
On success, the
Group object containing the details of the group is returned.
Get online group member count
To get the total count of online users in particular groups, you can use thegetOnlineGroupMemberCount() method.
- Dart
Map with the GUID of the group as the key and the online member count for that group as the value.
Offline Behaviour
With offline support enabled,GroupsRequest.fetchNext() with a GroupFetchListener first delivers onCachedGroups from the device (empty when nothing was recorded), then onServerGroups with the live page to reconcile by guid. Offline, the read ends with onError with code ERR_CONNECTION (details ERROR_INTERNET_UNAVAILABLE) after the cached page. A request that uses a server-only filter records nothing, so its cached page is always empty. See Show Cached Data.