Manage chat group members
Chat groups enable real-time messaging among multiple users.
This page shows how to use the Chat SDK to manage the members of a chat group in your app.
Understand the tech
The Chat SDK provides the Group
, GroupManager
, and GroupChangeListener
classes for chat group management, which allows you to implement the following features:
- Add and remove users from a chat group
- Manage the owner and admins of a chat group
- Manage the block list of a chat group
- Manage the mute list of a chat group
- Mute and unmute all the chat group members
- Manage the allow list of a chat group
Prerequisites
Before proceeding, ensure that you meet the following requirements:
- You have initialized the Chat SDK. For details, see Get Started with Android.
- You understand the call frequency limits of the Chat APIs supported by different pricing plans as described in Limitations.
- You understand the number of chat groups and chat group members supported by different pricing plans as described in Pricing Plan Details.
Implementation
This section describes how to call the APIs provided by the Chat SDK to implement chat group features.
Manage chat group members
-
Add users to a chat group.
Whether a chat group is public or private, the chat group owner and chat group admins can add users to the chat group. As for private groups, if the type of a chat group is set toGroupStylePrivateMemberCanInvite
, group members can invite users to join the chat group. -
Implement chat group invitations.
After a user is invited to join a chat group, the implementation logic varies based on the settings of the user:-
If the user requires a group invitation confirmation, the inviter receives the
onInvitationReceived
callback. Once the user accepts the request and joins the group, the inviter receives theonInvitationAccepted
callback and all group members receive theonMemberJoined
callback. Otherwise, the inviter receives theonInvitationDeclined
callback. -
If the user does not require a group invitation confirmation, the inviter receives the
onAutoAcceptInvitationFromGroup
callback. In this case, the user automatically accepts the group invitation and receives theonInvitationAccepted
callback. All group members receive theonMemberJoined
callback.
-
-
Remove chat group members from a chat group.
The chat group owner and chat group admins can remove chat group members from a chat group, whereas chat group members do not have this privilege. Once a group member is removed, all the other group members receive theonMemberExited
callback.
Refer to the following sample code to add and remove a user:
Manage chat group ownership and admin
-
Transfer the chat group ownership.
The chat group owner can transfer ownership to the specified chat group member. Once ownership is transferred, the original chat group owner becomes a group member. All the other chat group members receive theonOwnerChanged
callback. -
Add chat group admins.
The chat group owner can add admins. Once added to the chat group admin list, the newly added admin and the other chat group admins receive theonAdminAdded
callback. -
Remove chat group admins.
The chat group owner can remove admins. Once removed from the chat group admin list, the removed admin and the other chat group admins receive theonAdminRemoved
callback.
Refer to the following sample code the manage chat group ownership and admin:
Manage the chat group block list
The chat group owner and chat group admins can add or remove the specified member to the chat group block list. Once a chat group member is added to the block list, this member cannot send or receive chat group messages, nor can this member join the chat group again.
Refer to the following sample code to manage the chat group block list:
Manage the chat group mute list
The chat group owner and chat group admins can add or remove the specified member to the chat group mute list. Once a chat group member is added to the mute list, this member can no longer send chat group messages, not even after being added to the chat group allow list.
Refer to the following sample code to manage the chat group mute list:
Mute and unmute all the chat group members
The chat group owner and chat group admins can mute or unmute all the chat group members. Once all the members are muted, only those in the chat group allow list can send messages in the chat group.
Refer to the following sample code to mute and unmute all the chat group members:
Manage the chat group allow list
Members in the chat group allow list can send chat group messages even when the chat group owner or admin has muted all chat group members. However, if a member is already in the chat group mute list, adding this member to the allow list does not take effect.
Refer to the following sample code to manage the chat group allow list:
Listen for chat group events
For details, see [Chat Group Events]./manage-chat-groups#listen-for-chat-group-events).