Skip to main content

Retrieve the List of Group Members

In order to fetch the list of groups members for a group, you can use the GroupMembersRequest class. To use this class i.e to create an object of the GroupMembersRequest class, you need to use the GroupMembersRequestBuilder class. The GroupMembersRequestBuilder class allows you to set the parameters based on which the groups are to be fetched. The GroupMembersRequestBuilder class allows you to set the below parameters: The GUID of the group for which the members are to be fetched must be specified in the constructor of the GroupMembersRequestBuilder class.

Set Limit

This method sets the limit i.e. the number of members that should be fetched in a single iteration.

Set Search Keyword

With offline support on, this filter is answered by the server only; the cached page is empty.
This method allows you to set the search string based on which the group members are to be fetched.

Set Scopes

This method allows you to fetch group members based on the specified scopes.

Set Status

With offline support on, this filter is answered by the server only; the cached page is empty.
This method allows you to filter group members based on their online/offline status.
The status parameter can contain one of the below two values:
  • CometChatUserStatus.online - will return only online group members.
  • CometChatUserStatus.offline - will return only offline group members.
If this parameter is not set, all group members will be returned regardless of their status. Finally, once all the parameters are set to the builder class, you need to call the build() method to get the object of the GroupMembersRequest class. Once you have the object of the GroupMembersRequest class, you need to call the fetchNext() method. Calling this method will return a list of GroupMember objects containing N number of members depending on the limit set.
Starting with v5.1.0, `fetchNext()` accepts a listener: parameter. Pass a `GroupMemberFetchListener` 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.

Offline Behaviour

With offline support enabled, GroupMembersRequest.fetchNext() with a GroupMemberFetchListener first delivers onCachedGroupMembers from the device (empty when nothing was recorded), then onServerGroupMembers with the live page to reconcile by uid. 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.