CometChat Pro Documentation

You'll find comprehensive guides and documentation to help you start working with CometChat as quickly as possible. Let's jump right in!

Retrieve Group Members

Learn how to retrieve members of a group.

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.

  1. setLimit(int limit) - This method sets the limit i.e. the number of members that should be fetched in a single iteration.
GroupMembersRequest groupMembersRequest = new GroupMembersRequest.GroupMembersRequestBuilder(GUID)
.setLimit(limit)
.build();
  1. setSearchKeyword(String searchString) - This method allows you to set the search string based on which the group members are to be fetched.
GroupMembersRequest groupMembersRequest = new GroupMembersRequest.GroupMembersRequestBuilder(GUID)
.setSearchKeyword("abc")
.build();
  1. setScopes(List<String> scopes) - This method allows you to fetch group members based on the specified scopes.
List<String> scopes = new ArrayList<>();
scopes.add("admin");
scopes.add("moderator");
GroupMembersRequest groupMembersRequest = new GroupMembersRequest.GroupMembersRequestBuilder(GUID)
.setScopes(scopes)
.build();

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.

private GroupMembersRequest groupMembersRequest = null;
private String GUID = "GUID";
private int limit = 30;

groupMembersRequest = new GroupMembersRequest.GroupMembersRequestBuilder(GUID).setLimit(limit).build();

groupMembersRequest.fetchNext(new CometChat.CallbackListener<List<GroupMember>>(){
     @Override
     public void onSuccess(List<GroupMember> list) {
        Log.d(TAG, "Group Member list fetched successfully: " + list.size());
      }
     @Override
     public void onError(CometChatException e) {
      Log.d(TAG, "Group Member list fetching failed with exception: " + e.getMessage());
     }
            
 });
var groupMembersRequest:GroupMembersRequest?=null
val GUID:String="GUID"
val limit:Int=30

groupMembersRequest=GroupMembersRequest.GroupMembersRequestBuilder(GUID).setLimit(limit).build()

groupMembersRequest?.fetchNext(object:CometChat.CallbackListener<List<GroupMember>>(){
  override fun onSuccess(p0: List<GroupMember>?){
    Log.d(TAG, "Group Member list fetched successfully: " + p0?.size)
  }
  override fun onError(p0: CometChatException?) {
    Log.d(TAG, "Group Member list fetching failed with exception: " + p0?.message)
  }
})

Updated about a month ago


Retrieve Group Members


Learn how to retrieve members of a group.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.