Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cometchat-22654f5b-docs-android-v6-beta2.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

// Retrieve groups with pagination
GroupsRequest request = (GroupsRequestBuilder()
  ..limit = 30
  ..searchKeyword = "search_term"
).build();

await request.fetchNext(
  onSuccess: (List<Group> groups) {
    for (Group group in groups) {
      debugPrint("Group: ${group.name}");
    }
  },
  onError: (CometChatException e) => debugPrint("Error: ${e.message}"),
);

// Get a specific group by GUID
await CometChat.getGroup(
  "GROUP_ID",
  onSuccess: (Group group) => debugPrint("Group: ${group.name}"),
  onError: (CometChatException e) => debugPrint("Error: ${e.message}"),
);

// Fetch only joined groups
GroupsRequest joinedRequest = (GroupsRequestBuilder()
  ..limit = 30
  ..joinedOnly = true
).build();

// Get online member count
CometChat.getOnlineGroupMemberCount(["GUID"],
  onSuccess: (Map<String, int> count) => debugPrint("Count: $count"),
  onError: (CometChatException e) => debugPrint("Error: ${e.message}"),
);
Retrieve groups allows you to fetch the list of groups you’ve joined and groups that are available, as well as get details for a specific group.
Available via: SDK | REST API | UI Kits

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. Use GroupsRequestBuilder to fetch groups with filtering, searching, and pagination.

GroupsRequestBuilder

ParameterTypeDescription
limitint?Maximum number of groups to fetch per request. Max 100, default 30.
searchKeywordString?Search string to filter groups by name.
joinedOnlybool?When true, returns only groups the logged-in user has joined. Default false.
tagsList<String>?List of tags to filter groups by. Only groups with the specified tags are returned.
withTagsbool?When true, includes tag data in the returned group objects. Default false.
setPageint?Fetch groups from a particular page number.

Set Limit

Sets the number of groups to fetch per request.
GroupsRequest groupsRequest =  (GroupsRequestBuilder()
  ..limit= 20
).build();

Set Search Keyword

Filters groups by a search string.
GroupsRequest groupsRequest =  (GroupsRequestBuilder()
  ..limit= 20
  ..searchKeyword = "abc"  
).build();  

Joined Only

When true, returns only groups the logged-in user has joined or is a part of.
GroupsRequest groupsRequest =  (GroupsRequestBuilder()
  ..limit= 20
  ..joinedOnly = true
).build();

Set Tags

Filters groups by specified tags. The list fetched will only contain the groups that have been tagged with the specified tags.
List<String> tags =[];
tags.add("archived");
GroupsRequest groupsRequest =  (GroupsRequestBuilder()
  ..limit= 20
   ..tags = tags
).build();

With Tags

When true, includes tag data in the returned group objects.
GroupsRequest groupsRequest =  (GroupsRequestBuilder()
  ..limit= 20
  ..withTags = 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 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.
GroupsRequest groupsRequest =  (GroupsRequestBuilder()
  ..limit= 20
).build();

groupsRequest.fetchNext(onSuccess: (List<Group> groupList) {
    debugPrint("Fetched Group Successfully : $groupList ");
  }, onError: (CometChatException e) {
    debugPrint("Group Request failed with exception: ${e.message}");
  });
On Success — A List<Group> containing the fetched groups. Each Group object has the following structure:Group Object:
ParameterTypeDescriptionSample Value
guidstringUnique identifier for the group"cometchat-guid-1"
namestringDisplay name of the group"Tech Enthusiasts"
iconstringURL of the group iconnull
descriptionstringDescription of the group"A group for tech lovers"
membersCountnumberNumber of members in the group12
metadataobjectCustom metadata attached to the group{}
joinedAtnumberEpoch timestamp when the logged-in user joined the group1745554729
hasJoinedbooleanWhether the logged-in user has joined the grouptrue
createdAtnumberEpoch timestamp when the group was created1745554729
ownerstringUID of the group owner"cometchat-uid-1"
updatedAtnumberEpoch timestamp when the group was last updated1745554729
tagsarrayList of tags associated with the group[]
typestringType of the group (public, private, password)"public"
scopestringScope of the logged-in user in the group"admin"
passwordstringPassword for password-protected groupsnull
isBannedFromGroupbooleanWhether the logged-in user is banned from the groupfalse
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_CHAT_API_FAILURE"
messagestringHuman-readable error message"Failed to fetch the requested data."
detailsstringAdditional technical details"An unexpected error occurred while processing the request."

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.
String GUID = "GUID";

CometChat.getGroup(GUID, onSuccess: (Group group) {
      debugPrint("Fetched Group Successfully : $group ");
    }, onError: (CometChatException e) {
      debugPrint("Group Request failed with exception: ${e.message}");
    });
ParameterDescription
GUIDThe GUID of the group for whom the details are to be fetched
On success, the Group object containing the details of the group is returned.
On Success — A Group object containing all details of the requested group:Group Object:
ParameterTypeDescriptionSample Value
guidstringUnique identifier for the group"cometchat-guid-1"
namestringDisplay name of the group"Tech Enthusiasts"
iconstringURL of the group iconnull
descriptionstringDescription of the group"A group for tech lovers"
membersCountnumberNumber of members in the group12
metadataobjectCustom metadata attached to the group{}
joinedAtnumberEpoch timestamp when the logged-in user joined the group1745554729
hasJoinedbooleanWhether the logged-in user has joined the grouptrue
createdAtnumberEpoch timestamp when the group was created1745554729
ownerstringUID of the group owner"cometchat-uid-1"
updatedAtnumberEpoch timestamp when the group was last updated1745554729
tagsarrayList of tags associated with the group[]
typestringType of the group (public, private, password)"public"
scopestringScope of the logged-in user in the group"admin"
passwordstringPassword for password-protected groupsnull
isBannedFromGroupbooleanWhether the logged-in user is banned from the groupfalse
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_GUID_NOT_FOUND"
messagestringHuman-readable error message"The specified group does not exist."
detailsstringAdditional technical details"Please provide a valid GUID for the group."

Get online group member count

To get the total count of online users in particular groups, you can use the getOnlineGroupMemberCount() method.
List<String> guids =  [];
guids.add("cometchat-guid-1");
guids.add("cometchat-guid-11");

CometChat.getOnlineGroupMemberCount(guids,
        onSuccess: (Map<String, int> count) {
      debugPrint("Fetched Online Group Member Count Successfully : $count ");
    }, onError: (CometChatException e) {
      debugPrint("Online Group Member failed with exception: ${e.message}");
    });
This method returns a Map with the GUID of the group as the key and the online member count for that group as the value.
On Success — A Map<String, int> containing the GUID of each group as the key and the online member count as the value:Map Object:
ParameterTypeDescriptionSample Value
cometchat-guid-1numberOnline member count for the group3
cometchat-guid-11numberOnline member count for the group7
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_CHAT_API_FAILURE"
messagestringHuman-readable error message"Failed to fetch the requested data."
detailsstringAdditional technical details"An unexpected error occurred while processing the request."

Next Steps

Create Group

Create new public, private, or password-protected groups

Retrieve Members

Get the list of members in a group