Skip to main content

Documentation Index

Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt

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

// Fetch groups list
let request = GroupsRequest.GroupsRequestBuilder()
    .set(limit: 30).build()
request.fetchNext(onSuccess: { groups in }, onError: { error in })

// Get specific group details
CometChat.getGroup(GUID: "GUID", onSuccess: { group in }, onError: { error in })

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

// Get online member count
CometChat.getOnlineGroupMemberCount(["GUID"],
    onSuccess: { countData in }, onError: { error in })
Fetch the list of Group objects the logged-in user can see, get details for a specific group, or check online member counts.

Retrieve List of Groups

Use GroupsRequestBuilder to fetch groups with filtering, searching, and pagination.

Set Limit

Sets the number of groups to fetch per request.
let groupsRequest = GroupsRequest.GroupsRequestBuilder()
    .set(limit: 30)
    .build()

Set Search Keyword

Filters groups by a search string.
let groupsRequest = GroupsRequest.GroupsRequestBuilder()
    .set(searchKeyword: "abc")
    .set(limit: 30)
    .build()

Joined Only

When true, returns only groups the logged-in user has joined.
let groupsRequest = GroupsRequest.GroupsRequestBuilder()
    .set(joinedOnly: true)
    .set(limit: 30)
    .build()

Set Tags

Filters groups by specified tags.
let groupsRequest = GroupsRequest.GroupsRequestBuilder()
    .set(limit: 30)
    .set(tags: ["tag1", "tag2"])
    .build()

With Tags

When true, includes tag data in the returned group objects.
let groupsRequest = GroupsRequest.GroupsRequestBuilder()
    .set(limit: 30)
    .withTags(true)
    .build()
After configuring the builder, call build() to get the GroupsRequest object, then call fetchNext() to retrieve groups.
The list only includes public and password-protected groups. Private groups appear only if the user is a member.
let limit = 30

let groupsRequest = GroupsRequest.GroupsRequestBuilder(limit: limit).build()

groupsRequest.fetchNext(onSuccess: { (groups) in
    for group in groups {
        print("Group: \(group.stringValue())")
    }
}, onError: { (error) in
    print("Error: \(error?.errorDescription)")
})

Retrieve Particular Group Details

Use getGroup() to fetch a specific group’s details by GUID.
let guid = "cometchat-guid-1"

CometChat.getGroup(GUID: guid, onSuccess: { (group) in
    print("Group: \(group.stringValue())")
}, onError: { (error) in
    print("Error: \(error?.errorDescription)")
})
ParameterDescription
GUIDThe GUID of the group to fetch
The method returns a Group object.

Get Online Group Member Count

Use getOnlineGroupMemberCount() to get the number of online members in specified groups.
let guids = ["cometchat-guid-1", "cometchat-guid-2"]

CometChat.getOnlineGroupMemberCount(guids, onSuccess: { countData in
    // countData: [String: Int] - GUID as key, count as value
    for (guid, count) in countData {
        print("Group \(guid): \(count) online members")
    }
}, onError: { error in
    print("Error: \(error?.errorDescription)")
})
Returns a [String: Int] dictionary with GUIDs as keys and online member counts as values.

Next Steps

Create Group

Create public, private, or password-protected groups

Retrieve Group Members

Fetch and filter members of a specific group