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 Groups

Learn how to retrieve groups.

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 the GroupsRequest 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.

The GroupsRequestBuilder class allows you to set the below parameters:

  1. setLimit(limit: number) - This method sets the limit i.e. the number of groups that should be fetched in a single iteration.
var groupsRequest = new GroupsRequest.GroupsRequestBuilder()
  .setLimit(limit)
  .build();
  1. setSearchKeyword(searchString: string) - This method allows you to set the search string based on which the groups are to be fetched.
var groupsRequest = new GroupsRequest.GroupsRequestBuilder()
  .setSearchKeyword("abc")
  .build();
  1. joinedOnly(joinedOnly: boolean) - This method when used, will ask the SDK to only return the groups that the user has joined or is a part of.
var groupsRequest = new GroupsRequest.GroupsRequestBuilder()
  .joinedOnly(true)
  .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 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 where n is the limit set in the builder class.

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 the group.

var limit = 30;

var groupsRequest = new CometChat.GroupsRequestBuilder()
  .setLimit(limit)
  .build();

groupsRequest.fetchNext().then(
  groupList => {
    /* groupList will be the list of Group class */
    console.log("Groups list fetched successfully", groupList);
    /* you can display the list of groups available using groupList */
  },
  error => {
    console.log("Groups list fetching failed with error", error);
  }
);

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 the getGroup() method.

var GUID = "GUID";
CometChat.getGroup(GUID).then(
  group => {
    console.log("Group details fetched successfully:", group);
  },
  error => {
    console.log("Group details fetching failed with exception:", error);
  }
);

Parameter

Description

GUID

The GUID of the group for whom the details are to be fetched

It returns Group object containing the details of the group.

Updated 9 months ago


Retrieve Groups


Learn how to retrieve groups.

Suggested Edits are limited on API Reference Pages

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