Skip to main content
Quick Reference for AI Agents & Developers

Leave a Group

In order to stop receiving updates and messages for any particular joined group, you will have to leave the group using the leaveGroup() method.

Leave Group Parameters

Request Parameters:Success Response:After Leaving Group:Error Response (CometChatException):
Request Parameters:Error Response:
Group owner CANNOT leave the group. Owner must transfer ownership first using transferGroupOwnership().
Once a group is left, the user will not receive any updates or messages pertaining to the group.
Group owner CANNOT leave the group. Owner must transfer ownership first using transferGroupOwnership().

Real-time Leave Group Event

In other words, as a member of a group, how do I know if someone has left it? If a user leaves any group, the members of the group receive a real-time event in the onGroupMemberLeft() method of the CometChatGroupDelegate. In order to receive user Events, you must add protocol conformance CometChatGroupDelegate as shown below:
Event Trigger: Received via CometChatGroupDelegate.onGroupMemberLeft(action:leftUser:leftGroup:)ActionMessage Object:leftUser (User Object):leftGroup (Group Object):
Do not forget to set your view controller as a CometChat delegate probably in viewDidLoad() as CometChat.groupdelegate = self

Missed Group Member Left Events

In other words, as a member of a group, how do I know if someone has left it when my app is not running? When you retrieve the list of previous messages if a member has left any group that the logged-in user is a member of, the list of messages will contain an Action message. An Action message is a sub-class of BaseMessage class. For the group member left event, in the Action object received, the following fields can help you get the relevant information:

CometChatGroupDelegate

Listen for real-time group events by conforming to CometChatGroupDelegate.

Delegate Methods

Setup Configuration:Listening Status:Events Being Monitored:
Cleanup Configuration:Listening Status:
  • Set delegate in viewDidLoad(): CometChat.groupdelegate = self
  • Remove delegate when view is dismissed to avoid memory leaks

Common Error Codes