Skip to main content
Quick Reference for AI Agents & Developers
  • Build request: GroupsRequest.GroupsRequestBuilder().set(limit:).build()
  • Fetch groups: groupsRequest.fetchNext(onSuccess:onError:)
  • Get single group: CometChat.getGroup(GUID:onSuccess:onError:)
  • Online count: CometChat.getOnlineGroupMemberCount(_:onSuccess:onError:)
  • Filters: .set(searchKeyword:), .set(joinedOnly:), .set(tags:), .withTags(_:)
  • Related: Create Group · Join Group · Groups Overview

Group Data Model

The Group class represents a CometChat group with all its properties.

Group Properties

Group Object Properties:Metadata Properties (when present):

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.

GroupsRequestBuilder Methods

Builder Configuration:Common Filter Combinations:
  • fetchNext() returns public and password groups by default
  • Private groups only returned if user is a member
  • Use set(joinedOnly: true) to get only groups user has joined

Set Limit

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

Set Search Keyword

This method allows you to set the search string based on which the groups are to be fetched.

Joined Only

This method when used, will ask the SDK to only return the groups that the user has joined or is a part of.

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.

With Tags

This property when set to true will fetch tags data along with the list of groups.
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.
Request Parameters:Success Response (Array of Group Objects):Response Summary:Sample Group Entries:Error Response (CometChatException):
Request Parameters:Success Response (Array of Group Objects):Response Summary:
Request Parameters:Success Response (Array of Group Objects):Response Summary:
Request Parameters:Success Response (Array of Group Objects):Response Summary:

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.
On success, the Group object containing the details of the group is returned.
Request Parameters:Success Response (Group Object):Error Response (CometChatException):

Get Online Group Member Count

To get the total count of online users in particular groups, you can use the getOnlineGroupMemberCount() method.
This method returns a [String: Int] dictionary with the GUID as the key and the online member count for that group as the value.
Request Parameters:Success Response ([String: Int] Dictionary):Response Format:Error Response (CometChatException):

GroupType Enum

MemberScope Enum

Common Error Codes