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.
This section introduces how to call the APIs provided by the Chat SDK to implement the features listed above.
All the chat room members can call fetchChatRoomMembers
to retrieve the member list of the current chat room.
_1Map<String, Long> members = ChatClient.getInstance().chatroomManager().fetchChatRoomMembers(chatRoomId, cursor, pageSize);
The chat room owner and admin can call removeChatRoomMember
to remove the specified member 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.
_1ChatClient.getInstance().chatroomManager().removeChatRoomMembers(chatRoomId, members);
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.
_18// The chat room owner or admin call blockChatroomMembers to add the specified member to the chat room block list.
_18ChatRoom chatRoom = ChatClient.getInstance().chatroomManager().blockChatroomMembers(chatRoomId, members);
_18// The chat room owner or admin call unblockChatroomMembers to remove the specified user out of the block list.
_18ChatRoom chatRoom = ChatClient.getInstance().chatroomManager().unblockChatRoomMembers(chatRoomId, members);
_18// The chat room owner or admin call fetchChatRoomBlackList to reveive the block list of the current chat room.
_18ChatClient.getInstance().chatroomManager().fetchChatRoomBlackList(chatRoomId, new ValueCallBack<List<String>>() {
_18 public void onSuccess(List<String> value) {
_18 public void onError(int error, String errorMsg) {
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 message, not even after being added to the chat room allow list.
_8// The chat room owner or admin call muteChatRoomMembers to add the specified user to the chat room block list. The muted member and all the other chat room admins or owner receive the onMuteListAdded callback.
_8ChatRoom chatRoom = ChatClient.getInstance().chatroomManager().muteChatRoomMembers(chatRoomId, members, duration);
_8// The chat room owner or admin can call unMuteChatRoomMembers to remove the specified user from the chat room block list. The unmuted member and all the other chat room admins or owner receive the onMuteListRemoved callback.
_8ChatRoom chatRoom = ChatClient.getInstance().chatroomManager().unMuteChatRoomMembers(chatRoomId, members);
_8// The chat room owner or admin can call fetchChatRoomMuteList to fetch the mute list of the current chat room.
_8Map<String, Long> memberMap = ChatClient.getInstance().chatroomManager().fetchChatRoomMuteList(chatRoomId, pageNum, pageSize);
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.
_25// The chat room owner or admin can call muteAllMembers to mute all the chat room members. Once all the members are muted, these members receive the onAllMemberMuteStateChanged callback.
_25ChatClient.getInstance().chatroomManager().muteAllMembers(chatRoomId, new ValueCallBack<ChatRoom>() {
_25 public void onSuccess(ChatRoom value) {
_25 public void onError(int error, String errorMsg) {
_25// The chat room owner or admin can call unmuteAllMembers to unmute all the chat room members. Once all the members are unmuted, these members receive the onAllMemberMuteStateChanged callback.
_25ChatClient.getInstance().chatroomManager().unmuteAllMembers(chatRoomId, new ValueCallBack<ChatRoom>() {
_25 public void onSuccess(ChatRoom value) {
_25 public void onError(int error, String errorMsg) {
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, adding this member to the allow list does not take effect.
_51// The chat room owner or admin can call addToChatRoomWhiteList to add the specified member to the chat room allow list.
_51ChatClient.getInstance().chatroomManager().addToChatRoomWhiteList(chatRoomId, members, new ValueCallBack<ChatRoom>() {
_51 public void onSuccess(ChatRoom value) {
_51 public void onError(int error, String errorMsg) {
_51// The chat room owner or admin can call removeFromChatRoomWhiteList to add remove the specified member from the chat room allow list.
_51ChatClient.getInstance().chatroomManager().removeFromChatRoomWhiteList(chatRoomId, members, new ValueCallBack<ChatRoom>() {
_51 public void onSuccess(ChatRoom value) {
_51 public void onError(int error, String errorMsg) {
_51// Chat room members can call checkIfInChatRoomWhiteList to check whether they are in the chat room allow list.
_51ChatClient.getInstance().chatroomManager().checkIfInChatRoomWhiteList(chatRoomId, new ValueCallBack<Boolean>() {
_51 public void onSuccess(Boolean value) {
_51 public void onError(int error, String errorMsg) {
_51// The chat room owner or admin can call fetchChatRoomWhiteList to retrieve the allow list of the current chat room.
_51ChatClient.getInstance().chatroomManager().fetchChatRoomWhiteList(chatRoomId, new ValueCallBack<List<String>>() {
_51 public void onSuccess(List<String> value) {
_51 public void onError(int error, String errorMsg) {
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.
_8// The chat room owner can call changeOwner to transfer the ownership to the other chat room member.
_8ChatRoom chatRoom = ChatClient.getInstance().chatroomManager().changeOwner(chatRoomId, newOwner);
_8// The chat room owner can call addChatRoomAdmin to add the chat room admin.
_8ChatRoom chatRoom = ChatClient.getInstance().chatroomManager().addChatRoomAdmin(chatRoomId, admin);
_8// The chat room owner can call removeChatRoomAdmin to remove the chat room admin. The removed admin and the other admins receive the onAdminRemoved callback.
_8ChatRoom chatRoom = ChatClient.getInstance().chatroomManager().removeChatRoomAdmin(chatRoomId, admin);
For details, see Chat Room Events.