Manage chat room members
Chat rooms enable real-time messaging among multiple users.
This page shows how to use the Chat SDK to manage the members of a chat room in your app.
Understand the tech
The Chat SDK provides the ChatManager
and ChatRoom
classes for chat room management, which allows you to implement the following features:
- Remove a member from a chat room
- Retrieve the member list of a chat room
- Manage the block list of a chat room
- Manage the mute list of a chat room
- Mute and unmute all the chat room members
- Manage the chat room allow list
- Manage the owner and admins of a chat room
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 limit of the Chat APIs supported by different pricing plans as described in Limitations.
- You understand the number of chat rooms supported by different pricing plans as described in Pricing Plan Details.
Implementation
This section introduces how to call the APIs provided by the Chat SDK to implement the features listed above.
Manage chat room members
All the chat room members can call fetchChatRoomMembers
to retrieve the member list of the current chat room.
The chat room owner and admin can call removeChatRoomMembers
to remove one or more members from the chat room. Once a member is removed, this member receives the onRemovedFromChatRoom
callback, and the other chat room members receive the onMemberExited
callback. After being removed from a chat room, you can join this chat room again.
Manage the chat room block list
The chat room owner and admin can add the specified member into the chat room block list and remove them from it. Once a chat room member is added to the block list, this member cannot send or receive chat room messages, nor can this member join the chat room again.
Manage the chat room mute list
To manage the messages in the chat room, the chat room owner and admin can add the specified member to the chat room mute list and remove them from it. Once a chat room member is added to the mute list, this member can no longer send chat room messages, not even after being added to the chat room allow list.
Mute and unmute all the chat room members
The chat room owner or admin can mute or unmute all the chat room members using muteAllMembers
. Once all the members are muted, only those in the chat room allow list can send messages in the chat room.
Unlike muting a chat room 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 room.
Manage the chat room allow list
The chat room owner and admins are added to the chat room allow list by default.
Members in the chat room allow list can send chat room messages even when the chat room owner or admin has muted all the chat room members using muteAllMembers
. However, if a member is already in the chat room mute list, this member still cannot send messages in the chat room even after being added to the allow list of the chat room.
Messages sent by members in the chat room allow list are of high priority and will be delivered first, but there is no guarantee that they will be delivered. When the load is high, the server discards low-priority messages first. If the load is still high even then, the server discards high-priority messages.
Manage chat room ownership and admin
The chat room owner can transfer the ownership to the specified chat room member. Once the ownership is transferred, the original chat room owner becomes a regular member. The new chat room owner and the chat room admins receive the onOwnerChanged
callback.
The chat room owner can also add admins. Once added to the chat room admin list, the newly added admin and the other chat room admins receive the onAdminAdded
callback.
Listen for chat room events
For details, see Chat Room Events.