Skip to main content
Quick Reference - Leave a group:
await CometChat.leaveGroup("GUID");
Available via: SDK | REST API

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.
var GUID = "GUID"; // guid of the group to join

CometChat.leaveGroup(GUID).then(
hasLeft => {
  console.log("Group left successfully:", hasLeft);
}, error => {
  console.log("Group leaving failed with exception:", error);
}
);
ParameterDescription
GUIDThe UID of the group you would like to leave
Once a group is left, the user will no longer receive any updates or messages pertaining to the group.

Real-time Group Member Left Events

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 GroupListener class.
CometChat.addGroupListener(
  "UNIQUE_LISTENER_ID",
  new CometChat.GroupListener({
      onGroupMemberLeft: (message, leavingUser, group) => {
          console.log("User left", { message, leavingUser, group });
      }
  })
);
Always remove group listeners when the component unmounts using CometChat.removeGroupListener(listenerId). Failing to remove listeners can cause memory leaks and duplicate event handling.

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-
  1. action - left
  2. actionBy - User object containing the details of the user who left the group
  3. actionFor - Group object containing the details of the group the user has left

Best Practices

After successfully leaving a group, remove any local references to the group’s messages, members, or conversation data. This prevents stale data from appearing in your UI.
If the logged-in user is the group owner, consider transferring ownership to another admin or member before leaving. Leaving as the owner may have different behavior depending on your app’s configuration.

Troubleshooting

Verify the GUID is correct and the logged-in user is actually a member of the group. You can check membership using getGroup() and the hasJoined property.
Ensure the leaveGroup() call completed successfully (resolved the promise). Also remove any active group listeners for that group to stop receiving real-time events.

Next Steps