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 SDK quickstart.
- 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.
Does a group invitation require consent from an invitee to add them to the group (
inviteNeedConfirm
):-
Yes (
option.InviteNeedConfirm
is set totrue
). After creating a group and sending group invitations, the subsequent logic varies based on whether an invitee automatically consents to the group invitation (autoAcceptGroupInvitation
):- Yes (
autoAcceptGroupInvitation
is set totrue
). The invitee automatically joins the chat group and receives theGroupChangeListener#onAutoAcceptInvitationFromGroup
callback, the inviter receives theGroupChangeListener#onInvitationAccepted
andGroupChangeListeneronMemberJoined
callbacks, and the other chat group members receive theGroupChangeListener#onMemberJoined
callback. - No (
autoAcceptGroupInvitation
is set tofalse
). The invitee receives the GroupChangeListener#onInvitationReceived callback and chooses whether to join the chat group:- If the invitee accepts the group invitation, the inviter receives the
GroupChangeListener#onInvitationAccepted
andGroupChangeListener#onMemberJoined
callbacks and the other chat group members receive theGroupChangeListener#onMemberJoined
callback; - If the invitee declines the group invitation, the chat group owner receives the
GroupChangeListener#groupInvitationDidDecline
callback.
- If the invitee accepts the group invitation, the inviter receives the
- Yes (
-
No (
option.InviteNeedConfirm
is set tofalse
). After creating a chat group and sending group invitations, an invitee is added to the chat group regardless of theirautoAcceptGroupInvitation
setting. The invitee receives theGroupChangeListener#onAutoAcceptInvitationFromGroup
callback, the inviter receives theGroupChangeListener#onInvitationAccepted
andGroupChangeListener#onMemberJoined
callbacks and the other chat group members receive theGroupChangeListener#onMemberJoined
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, the removed member receives theonUserRemoved
callback and all other members in the group 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. The new owner receives the
onOwnerChanged
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.
Unlike muting a chat group member, this kind of mute does not expire automatically after a certain period and you need to call the unmuteAllMembers
method to unmute all members 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
The chat group owner and admins are added to the chat group allow list by default.
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, this member still cannot send messages in the group even after being added to the group allow list.
Refer to the following sample code to manage the chat group allow list:
Listen for chat group events
For details, see Chat Group Events.