Quick Reference for AI Agents & Developers
- Update group:
CometChat.updateGroup(group:onSuccess:onError:) - Updatable fields: name, description, icon, metadata, tags
- Permission: Only group owner or admin can update
- Related: Create Group · Delete Group · Groups Overview
Update Group
In other words, as a group owner, how can I update the group details? You can update the existing details of the group using theupdateGroup() method.
- Swift
- Objective C
Group class as a parameter that should contain the data that you wish to update.
| Parameter | Description |
|---|---|
| group | an instance of class Group |
Group class containing update information of the group.
Sample Payload - updateGroup() Request
Sample Payload - updateGroup() Request
Method Signature:
Group Object (Input):
Updatable Properties:
Non-Updatable Properties:
Prerequisites:
| Parameter | Type | Description |
|---|---|---|
| group | Group | Group object with updated properties |
| onSuccess | (Group) -> Void | Success callback with updated Group object |
| onError | (CometChatException?) -> Void | Error callback with exception details |
| Parameter | Type | Description |
|---|---|---|
| guid | String | Unique group identifier (required). Example: "cometchat-guid-1" |
| name | String | Updated group name. Example: "Updated Test Group" |
| groupType | GroupType | Group type (required). Example: .public |
| icon | String? | Updated group icon URL. Example: "https://example.com/new-icon.png" |
| description | String? | Updated group description. Example: "Updated description" |
| metadata | [String: Any]? | Updated custom metadata. Example: ["key": "value"] |
| tags | [String]? | Updated group tags. Example: ["updated", "team"] |
| password | String? | Password (required for password-protected groups). Example: nil |
| Property | Type | Description |
|---|---|---|
| name | String | Group display name |
| icon | String? | Group icon URL |
| description | String? | Group description text |
| metadata | [String: Any]? | Custom key-value metadata |
| tags | [String] | Array of searchable tags |
| Property | Description |
|---|---|
| guid | Cannot be changed after creation |
| groupType | Cannot be changed after creation |
| owner | Use Transfer Ownership instead |
| membersCount | Automatically managed by system |
| createdAt | Set at creation time |
| Requirement | Description |
|---|---|
| User logged in | User must be authenticated via CometChat.login() |
| Owner/Admin permission | User must be the owner or admin of the group |
| Valid GUID | Group with specified GUID must exist |
| Valid name | Group name cannot be empty |
Sample Payload - updateGroup() Success Response
Sample Payload - updateGroup() Success Response
Success Callback Parameter:
Updated Group Object:
GroupType Enum Values:
MemberScope Enum Values:
Real-time Event Triggered:
| Parameter | Type | Description |
|---|---|---|
| group | Group | Updated Group object. See Group Object below |
| Parameter | Type | Description |
|---|---|---|
| guid | String | Group’s unique ID. Example: "cometchat-guid-1" |
| name | String | Updated group name. Example: "Updated Test Group" |
| groupType | GroupType | Group type. Example: .public |
| icon | String? | Updated icon URL. Example: "https://example.com/new-icon.png" |
| description | String? | Updated description. Example: "Updated description" |
| owner | String | Group owner UID. Example: "cometchat-uid-1" |
| membersCount | Int | Number of members. Example: 15 |
| createdAt | Int | Creation timestamp. Example: 1699700000 |
| updatedAt | Int | Update timestamp. Example: 1699800000 |
| hasJoined | Bool | Whether current user has joined. Example: true |
| joinedAt | Int | Join timestamp. Example: 1699710000 |
| scope | MemberScope | Current user’s scope. Example: .admin |
| metadata | [String: Any]? | Updated custom metadata |
| tags | [String] | Updated group tags |
| Value | Description |
|---|---|
| .public | Anyone can join without approval |
| .private | Requires invitation to join |
| .password | Requires password to join |
| Value | Description |
|---|---|
| .admin | Administrator privileges (can update group) |
| .moderator | Moderator privileges |
| .participant | Regular member (cannot update group) |
| Event | Delegate Method | Description |
|---|---|---|
| onGroupUpdated | CometChatGroupDelegate | Notifies all group members of the update |
Sample Payload - updateGroup() Error Response
Sample Payload - updateGroup() Error Response
Error Callback Parameter:
CometChatException Object:
Common Error Codes:
Error Response Example (Not a Member):
Error Response Example (Permission Denied):
Error Response Example (Group Not Found):
| Parameter | Type | Description |
|---|---|---|
| error | CometChatException? | Error object containing failure details |
| Parameter | Type | Description |
|---|---|---|
| errorCode | String | Machine-readable error code. Example: "ERR_NOT_A_MEMBER" |
| errorDescription | String | Human-readable error message |
| errorDetails | [String: Any]? | Additional error context |
| Error Code | Description | Resolution |
|---|---|---|
| ERR_NOT_LOGGED_IN | User is not logged in | Login first using CometChat.login() |
| ERR_GUID_NOT_FOUND | Group does not exist | Verify the GUID is correct |
| ERR_GROUP_NOT_FOUND | Group does not exist | Verify the GUID is correct |
| ERR_NOT_A_MEMBER | User is not a member of the group | Join the group first |
| ERR_PERMISSION_DENIED | No permission to update | Only owner or admin can update |
| ERR_EMPTY_GROUP_NAME | Group name is empty | Provide a valid group name |
| ERR_INVALID_GUID | GUID format is invalid | Provide a valid GUID string |
| Parameter | Type | Description |
|---|---|---|
| errorCode | String | Example: "ERR_NOT_A_MEMBER" |
| errorDescription | String | Example: "The user with UID cometchat-uid-2 is not a member of group with GUID Cometchat-guid-1." |
| Parameter | Type | Description |
|---|---|---|
| errorCode | String | Example: "ERR_PERMISSION_DENIED" |
| errorDescription | String | Example: "Only the owner or admin can update this group." |
| Parameter | Type | Description |
|---|---|---|
| errorCode | String | Example: "ERR_GUID_NOT_FOUND" |
| errorDescription | String | Example: "Group with the specified GUID does not exist." |
Sample Payload - getGroup() Request (Pre-Update Fetch)
Sample Payload - getGroup() Request (Pre-Update Fetch)
Method Signature:
Request Parameters:
Use Case:
| Parameter | Type | Description |
|---|---|---|
| GUID | String | Group identifier to fetch. Example: "cometchat-guid-1" |
| onSuccess | (Group) -> Void | Success callback with Group object |
| onError | (CometChatException?) -> Void | Error callback with exception details |
| Parameter | Type | Description |
|---|---|---|
| guid | String | The unique identifier of the group to fetch. Example: "Cometchat-guid-1" |
| Step | Action | Description |
|---|---|---|
| 1 | Fetch group | Call CometChat.getGroup(GUID:) to get current group details |
| 2 | Modify properties | Update desired properties on the returned Group object |
| 3 | Update group | Call CometChat.updateGroup(group:) with modified object |
Sample Payload - getGroup() Error Response
Sample Payload - getGroup() Error Response
Error Callback Parameter:
Error Response Example:
Common getGroup() Error Codes:
| Parameter | Type | Description |
|---|---|---|
| error | CometChatException? | Error object containing failure details |
| Parameter | Type | Description |
|---|---|---|
| errorCode | String | Example: "ERR_NOT_A_MEMBER" |
| errorDescription | String | Example: "The user with UID cometchat-uid-2 is not a member of group with GUID Cometchat-guid-1." |
| Error Code | Description |
|---|---|
| ERR_NOT_LOGGED_IN | User is not logged in |
| ERR_GUID_NOT_FOUND | Group does not exist |
| ERR_NOT_A_MEMBER | User is not a member of the group |
| ERR_INVALID_GUID | GUID format is invalid |
Real-time Events
When a group is updated, all members receive theonGroupUpdated event via CometChatGroupDelegate:
- Swift
Sample Payload - onGroupUpdated Event
Sample Payload - onGroupUpdated Event
Delegate Method Parameters:
ActionMessage Object:
| Parameter | Type | Description |
|---|---|---|
| action | ActionMessage | Action message describing the update |
| updatedGroup | Group | The updated Group object |
| updatedBy | User | User who performed the update |
updatedBy User Object:
| Parameter | Type | Description |
|---|---|---|
| uid | String | User’s unique ID. Example: "cometchat-uid-1" |
| name | String | User’s display name. Example: "John Doe" |
| avatar | String? | User’s avatar URL |
| status | UserStatus | Online status. Example: .online |