For AI agents: see the complete documentation index at /llms.txt.
Manage chat group members
Updated
Introduces chat group functionalities.
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:
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 to
GroupStylePrivateMemberCanInvite, 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.InviteNeedConfirmis 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 (
autoAcceptGroupInvitationis set totrue). The invitee automatically joins the chat group and receives theGroupChangeListener#onAutoAcceptInvitationFromGroupcallback, the inviter receives theGroupChangeListener#onInvitationAcceptedandGroupChangeListener#onMembersJoinedcallbacks, and the other chat group members receive theGroupChangeListener#onMembersJoinedcallback. - No (
autoAcceptGroupInvitationis 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#onInvitationAcceptedandGroupChangeListener#onMembersJoinedcallbacks and the other chat group members receive theGroupChangeListener#onMembersJoinedcallback; - If the invitee declines the group invitation, the chat group owner receives the
GroupChangeListener#groupInvitationDidDeclinecallback.
- If the invitee accepts the group invitation, the inviter receives the
- Yes (
-
No (
option.InviteNeedConfirmis set tofalse). After creating a chat group and sending group invitations, an invitee is added to the chat group regardless of theirautoAcceptGroupInvitationsetting. The invitee receives theGroupChangeListener#onAutoAcceptInvitationFromGroupcallback, the inviter receives theGroupChangeListener#onInvitationAcceptedandGroupChangeListener#onMembersJoinedcallbacks and the other chat group members receive theGroupChangeListener#onMembersJoinedcallback.
-
-
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 the
onUserRemovedcallback and all other members in the group receive theonMembersExitedcallback.
Refer to the following sample code to add and remove a user:
// The chat group owner and chat group admins can call addUsersToGroup to add users to a chat group.
ChatClient.getInstance().groupManager().addUsersToGroup(groupId, newmembers);
// Chat group members can call inviteUser to invite users to a chat group.
ChatClient.getInstance().groupManager().inviteUser(groupId, newmembers, null);
// The chat group owner and chat group admins can call removeUserFromGroup to remove a member from a chat group.
ChatClient.getInstance().groupManager().removeUserFromGroup(groupId, username);
// The chat group owner and chat group admins can call asyncRemoveUsersFromGroup to remove members from a chat group.
ChatClient.getInstance().groupManager().asyncRemoveUsersFromGroup("GroupId", userList, new CallBack() {
@Override
public void onSuccess() {
}
@Override
public void onError(int code, String error) {
}
});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
onOwnerChangedcallback. -
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 the
onAdminAddedcallback. -
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 the
onAdminRemovedcallback.
Refer to the following sample code the manage chat group ownership and admin:
// The chat group owner can call changeOwner to transfer ownership to the specified chat group member.
ChatClient.getInstance().groupManager().changeOwner(groupId, newOwner);
// The chat group owner can call `addGroupAdmin` to add admins.
ChatClient.getInstance().groupManager().addGroupAdmin(groupId, admin);
// The chat group owner can call `removeGroupAdmin` to remove admins.
ChatClient.getInstance().groupManager().removeGroupAdmin(groupId, admin);Manage the chat group blocklist
The chat group owner and chat group admins can add or remove the specified member to the chat group blocklist. Once a chat group member is added to the blocklist, 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 blocklist:
// The chat group owner and admins can call blockUser to add the specified member to the chat group blocklist.
ChatClient.getInstance().groupManager().blockUser(groupId, username);
// The chat group owner and admins can call unblockUser to remove the specified member from the chat group blocklist.
ChatClient.getInstance().groupManager().unblockUser(groupId, username);
// The chat group owner and admins can call getBlockedUsers to retrieve the chat group blocklist.
ChatClient.getInstance().groupManager().getBlockedUsers(groupId);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:
// The chat group owner and admins can call muteGroupMember to add the specified member to the chat group mute list. The muted member and all the other chat group admins or owner receive the onMuteListAdded callback.
// duration: The mute duration. If you pass `-1`, members are muted permanently.
ChatClient.getInstance().groupManager().muteGroupMembers(groupId, muteMembers, duration);
// The chat group owner and admins can call unmuteGroupMember to remove the specified user from the chat group mute list. The unmuted member and all the other chat group admins or owner receive the onMuteListRemoved callback.
ChatClient.getInstance().groupManager().unMuteGroupMembers(String groupId, List members);
// The chat group owner or admin can call fetchGroupMuteList to retrieve the chat group mute list.
ChatClient.getInstance().groupManager().fetchGroupMuteList(String groupId, int pageNum, int pageSize);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:
// The chat group owner or admin can call muteAllMembers to mute all the chat group members. Once all the members are muted, these members receive the onAllMemberMuteStateChanged callback.
public void muteAllMembers(final String groupId, final ValueCallBack callBack);
// The chat group owner or admin can call unmuteAllMembers to unmute all the chat group members. Once all the members are unmuted, these members receive the onAllMemberMuteStateChanged callback.
public void unmuteAllMembers(final String groupId, final ValueCallBack callBack);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:
// The chat group owner or admin can call addToChatGroupWhiteList to add the specified member to the chat group allow list. Once the member is added, all the other chat group admins or owner receive the onWhiteListAdded callback.
public void addToGroupWhiteList(final String groupId, final List members, final CallBack callBack);
// The chat group owner or admin can call removeFromChatGroupWhiteList to remove the specified member from the chat group list. Once the member is removed, all the other chat group admins or owner receive the onWhiteListRemoved callback.
public void removeFromGroupWhiteList(final String groupId, final List members, final CallBack callBack);
// Chat group members can call checkIfInChatGroupWhiteList to check whether they are in the chat group allow list.
public void checkIfInGroupWhiteList(final String groupId, ValueCallBack callBack);
// The chat group owner or admin can call fetchChatGroupWhiteList to retrieve the chat group allow list.
public void fetchGroupWhiteList(final String groupId, final ValueCallBack> callBack);Listen for chat group events
For details, see Chat Group Events.
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 IAgoraChatGroupManager, AgoraChatGroupManagerDelegate, and AgoraChatGroup classes for chat group management, which allows you to implement the following features:
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 to
AgoraChatGroupStylePrivateMemberCanInvite, 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
groupInvitationDidReceivecallback. Once the user accepts the request and joins the group, the user receives thegroupInvitationDidAcceptcallback and all group members receive theuserDidJoinGroupcallback. Otherwise, the user receives thegroupInvitationDidDeclinecallback. - If the user does not require a group invitation confirmation, the user receives the
groupInvitationDidAcceptcallback. In this case, the user automatically accepts the group invitation and receives thedidJoinGroupcallback. All group members receive theuserDidJoinGroupcallback.
- If the user requires a group invitation confirmation, the inviter receives the
-
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 group member receives the
didLeaveGroupcallback and all the other group members receive theuserDidLeaveGroupcallback.
Refer to the following sample code to add and remove a user:
// Group members can call addMembers to add users to a chat group.
[[AgoraChatClient sharedClient].groupManager addMembers:@{@"member1",@"member2"}
toGroup:@"groupID"
message:@"message"
completion:nil];
// The chat group owner and chat group admins can call removeMembers to remove group members from a chat group.
[[AgoraChatClient sharedClient].groupManager removeMembers:@{@"member"}
fromGroup:@"groupsID"
completion:nil];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
groupOwnerDidUpdatecallback. -
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 the
groupAdminListDidUpdatecallback. -
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 the
groupAdminListDidUpdatecallback.
Refer to the following sample code to manage chat group ownership and admin:
// The chat group owner can call updateGroupOwner to transfer ownership to the specified chat group member.
[[AgoraChatClient sharedClient].groupManager updateGroupOwner:@"groupID"
newOwner:@"newOwner"
error:nil];
// The chat group owner can call addAdmin to add admins.
[[AgoraChatClient sharedClient].groupManager addAdmin:@"member"
toGroup:@"groupID"
error:nil];
// The chat group owner can call removeAdmin to remove admins.
[[AgoraChatClient sharedClient].groupManager removeAdmin:@"admin"
fromGroup:@"groupID"
error:nil];Manage the chat group blocklist
The chat group owner and chat group admins can add or remove the specified member to the chat group blocklist. Once a chat group member is added to the blocklist, 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 blocklist:
// The chat group owner and admins can call blockMembers to add the specified member to the chat group blocklist.
[[AgoraChatClient sharedClient].groupManager blockMembers:members
fromGroup:@"groupID"
completion:nil];
// The chat group owner and admins can call unblockMembers to remove the specified member from the chat group blocklist.
[[AgoraChatClient sharedClient].groupManager unblockMembers:members
fromGroup:@"groupId"
completion:nil];
// The chat group owner and admins can call getGroupBlacklistFromServerWithId to retrieve the chat group blocklist.
[[AgoraChatClient sharedClient].groupManager getGroupBlacklistFromServerWithId:@"groupId"
pageNumber:pageNumber
pageSize:pageSize
completion:nil];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:
// The chat group owner and admins can call muteMembers to add the specified member to the chat group mute list.
// The muted member and all the other chat group admins or owner receive the groupMuteListDidUpdate callback.
// muteMilliseconds: The mute duration. If you pass `-1`, members are muted permanently.
[[AgoraChatClient sharedClient].groupManager muteMembers:members
muteMilliseconds:60
fromGroup:@"groupID"
error:nil];
// The chat group owner and admins can call unmuteMembers to remove the specified user from the chat group mute list.
// The unmuted member and all the other chat group admins or owner receive the groupMuteListDidUpdate callback.
[[AgoraChatClient sharedClient].groupManager unmuteMembers:members
fromGroup:@"groupID"
error:nil];
// The chat group owner or admin can call getGroupMuteListFromServerWithId to retrieve the chat group mute list.
[[AgoraChatClient sharedClient].groupManager getGroupMuteListFromServerWithId:@"groupID"
pageNumber:pageNumber
pageSize:pageSize
error:nil];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. Once a chat group member is added to the chat group mute list, the member can no longer send chat group messages, not even after being added to the chat group allow list.
As the mute does not expire in a certain period, you need to call the API of unmuting all chat group members to stop muting them.
Refer to the following sample code to mute and unmute all the chat group members:
// The chat group owner or admin can call muteAllMembersFromGroup to mute all the chat group members.
// Once all the members are muted, these members receive the groupAllMemberMuteChanged callback.
[[AgoraChatClient sharedClient].groupManager muteAllMembersFromGroup:@"groupID"
error:nil];
// The chat group owner or admin can call unmuteAllMembersFromGroup to unmute all the chat group members.
// Once all the members are unmuted, these members receive the groupAllMemberMuteChanged callback.
[[AgoraChatClient sharedClient].groupManager unmuteAllMembersFromGroup:@"groupID"
error:nil];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 allow list.
Refer to the following sample code to manage the chat group allow list:
// The chat group owner or admin can call addWhiteListMembers to add the specified member to the chat group allow list.
// Once the member is added, all the other chat group admins or owner receive the groupWhiteListDidUpdate callback.
[[AgoraChatClient sharedClient].groupManager addWhiteListMembers:members
fromGroup:@"groupID"
error:nil];
// The chat group owner or admin can call removeWhiteListMembers to remove the specified member from the chat group list.
// Once the member is removed, all the other chat group admins or owner receive the groupWhiteListDidUpdate callback.
[[AgoraChatClient sharedClient].groupManager removeWhiteListMembers:members
fromGroup:@"groupID"
error:nil];
// Chat group members can call isMemberInWhiteListFromServerWithGroupId to check whether they are in the chat group allow list.
[[AgoraChatClient sharedClient].groupManager
isMemberInWhiteListFromServerWithGroupId:@"groupID"
error:nil];
// The chat group owner or admin can call getGroupWhiteListFromServerWithId to retrieve the chat group allow list.
[[AgoraChatClient sharedClient].groupManager getGroupWhiteListFromServerWithId:@"groupID" error:nil];Listen for chat group events
For details, see Chat Group Events.
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 ChatGroup, ChatGroupManager, and ChatGroupEventHandler classes for chat group management, which allows you to implement the following features:
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.
Add a user to a chat group
The logic of adding a user to a chat group varies according to the GroupStyle and inviteNeedConfirm settings when creating the chat group. For details, see Create a Chat Group.
The following code sample shows how to call addMembers to add a user to a chat group:
try {
await ChatClient.getInstance.groupManager.addMembers(groupId, members);
} on ChatError catch (e) {
}Remove a member from a chat group
Only the chat group owner and admins can call removeMembers to remove one or more members from a chat group. Once removed from the chat group, the member receives the ChatGroupEventHandler#onUserRemovedFromGroup callback, while all the other members receive the ChatGroupEventHandler#onMembersExitedFromGroup callback. Users can join the chat group again after being removed.
The following code sample shows how to remove a member from a chat group:
try {
await ChatClient.getInstance.groupManager.removeMembers(groupId, members);
} on ChatError catch (e) {
}Manage the chat group owner and admins
Transfer the chat group ownership
Only the chat group owner can call changeOwner to transfer the ownership to the specified chat group member. Once the ownership is transferred, the former chat group owner becomes a regular member, and the new owner receives the ChatGroupEventHandler#onOwnerChangedFromGroup callback.
The following code sample shows how to transfer the chat group ownership:
try {
await ChatClient.getInstance.groupManager.changeOwner(groupId, newOwner);
} on ChatError catch (e) {
}Add a chat group admin
Only the chat group owner can call addAdmin to add an admin. Once promoted to an admin, the new admin and the other chat group admins receive the ChatGroupEventHandler#onAdminAddedFromGroup callback.
The following code sample shows how to add a chat group admin:
try {
ChatClient.getInstance.groupManager.addAdmin(groupId, memberId);
} on ChatError catch (e) {
}Remove a chat group admin
Only the chat group owner can call removeAdmin to remove an admin. Once demoted to a regular member, the former admin and the other chat group admins receive the ChatGroupEventHandler#onAdminRemovedFromGroup callback.
The following code sample shows how to remove a chat group admin:
try {
await ChatClient.getInstance.groupManager.removeAdmin(groupId, adminId);
} on ChatError catch (e) {
}Manage the chat group blocklist
Add a member to the chat group blocklist
Only the chat group owner and admins can call blockMembers to add the specified member to the chat group blocklist. Once added to the blocklist, this member receives the ChatGroupEventHandler#onUserRemovedFromGroup callback, while all the other members receive the ChatGroupEventHandler#onMembersExitedFromGroup callback. After being added to blocklist, this user cannot send or receive messages in the chat group. They can no longer join the chat room until they are removed from the blocklist.
The following code sample shows how to add a member to the chat group blocklist:
try {
await ChatClient.getInstance.groupManager.blockMembers(groupId, members);
} on ChatError catch (e) {
}Remove a member from the chat group blocklist
Only the chat group owner and admins can call unblockMembers to remove the specified member from the chat group blocklist.
The following code sample shows how to remove a member from the chat group blocklist:
try {
await ChatClient.getInstance.groupManager.unblockMembers(groupId, blockIds);
} on ChatError catch (e) {
}Retrieve the chat group blocklist
Only the chat group owner and admins can call fetchBlockListFromServer to retrieve the chat group blocklist.
The following code sample shows how to retrieve the chat group blocklist:
try {
await ChatClient.getInstance.groupManager.fetchBlockListFromServer(
groupId,
pageNum: pageNum,
pageSize: pageSize,
);
} on ChatError catch (e) {
}Manage the chat group mute list
Add a member to the chat group mute list
Only the chat group owner and admins can call muteMembers to add the specified member to the chat group mute list. Once added to the mute list, this member and all the other chat group admins or owner receive the ChatGroupEventHandler#onMuteListAddedFromGroup callback. Once a chat group member is added to the chat group mute list, they can no longer send chat group messages, not even after being added to the chat group allow list.
The following code sample shows how to add a member to the chat group mute list:
// duration: The mute duration. If you pass `-1`, members are muted permanently.
try {
await ChatClient.getInstance.groupManager.muteMembers(
groupId,
members,
);
} on ChatError catch (e) {
}Remove a member from the chat group mute list
Only the chat group owner and admins can call unMuteMembers to remove the specified member from the chat group mute list. Once removed from the chat group mute list, this member and all the other chat group admins or owner receive the ChatGroupEventHandler#onMuteListRemovedFromGroup callback.
The following code sample shows how to remove a member from the chat group mute list:
try {
await ChatClient.getInstance.groupManager.unMuteMembers(
groupId,
members,
);
} on ChatError catch (e) {
}Retrieve the chat group mute list
Only the chat group owner and admins can call fetchMuteListFromServer to retrieve the chat group mute list from the server.
The following code sample shows how to retrieve the chat group mute dictionary:
try {
await ChatClient.getInstance.groupManager.fetchMuteListFromServer(
groupId,
pageNum: pageNum,
pageSize: pageSize,
);
} on ChatError catch (e) {
}Mute all the chat group members
Only the chat group owner and admins can call muteAllMembers to mute all the chat group members. All members in the group can receive the ChatGroupEventHandler#onAllMemberMuteStateChanged event.
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.
The following sample code shows how to mute all the chat group members:
try {
await ChatClient.getInstance.groupManager.muteAllMembers(
groupId,
);
} on ChatError catch (e) {
}Unmute all the chat group members
Only the chat group owner and admins can call unMuteAllMembers to unmute all the chat group members. All members in the group can receive the ChatGroupEventHandler#onAllMemberMuteStateChanged event.
The following sample code shows how to unmute all the chat group members:
try {
await ChatClient.getInstance.groupManager.unMuteAllMembers(
groupId,
);
} on ChatError catch (e) {
}Manage the chat group allow list
The chat group owner and admins are added to the chat group allow list by default.
Add a member to the chat group allow list
Only the chat group owner and admins can call addAllowList to add the specified member to 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, this member still cannot send messages in the group even after being added to the group allow list.
The following code sample shows how to add a member to the chat group allow list:
try {
await ChatClient.getInstance.groupManager.addAllowList(
groupId,
members,
);
} on ChatError catch (e) {
}Remove a member from the chat group allow list
Only the chat group owner and admins can call removeAllowList to remove the specified member from the chat group allow list.
The following code sample shows how to remove a member from the chat group allow list:
try {
await ChatClient.getInstance.groupManager.removeAllowList(
groupId,
members,
);
} on ChatError catch (e) {
}Check whether a user is added to the allow list
All chat group members can call isMemberInAllowListFromServer to check whether they are added to the chat group allow list.
The following code sample shows how to check whether a user is on the chat group allow list:
try {
bool check = await ChatClient.getInstance.groupManager.isMemberInAllowListFromServer(
groupId,
);
} on ChatError catch (e) {
}Retrieve the chat group allow list
Only the chat group owner and admins can call fetchAllowListFromServer to retrieve the chat group allow list.
The following code sample shows how to retrieve the chat group allow list:
try {
List? list =
await ChatClient.getInstance.groupManager.fetchAllowListFromServer(
groupId,
);
} on ChatError catch (e) {
}Listen for chat group events
For details, see Chat Group Events.
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 ChatGroup, ChatGroupManager, and ChatGroupEventListener classes for chat group management, which allows you to implement the following features:
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.
Add a user to a chat group
The logic of adding a user to a chat group varies according to the GroupStyle and inviteNeedConfirm settings when creating the chat group. For details, see Create a Chat Group.
The following code sample shows how to call addMembers to add a user to a chat group:
const groupId = "100";
const members = ["Tom", "Json"];
const welcome = "Welcome to you";
ChatClient.getInstance()
.groupManager.addMembers(groupId, members, welcome)
.then(() => {
console.log("add members success.");
})
.catch((reason) => {
console.log("add members fail.", reason);
});Remove a member from a chat group
Only the chat group owner and admins can call removeMembers to remove one or more members from a chat group. Once removed from the chat group, the member receives the ChatGroupEventListener#onUserRemoved callback, while all the other members receive the ChatGroupEventListener#onMembersExited callback. Users can join the chat group again after being removed.
The following code sample shows how to remove a member from a chat group:
ChatClient.getInstance()
.groupManager.removeMembers(groupId, members)
.then(() => {
console.log("remove members success.");
})
.catch((reason) => {
console.log("remove members fail.", reason);
});Manage the chat group owner and admins
Transfer the chat group ownership
Only the chat group owner can call changeOwner to transfer the ownership to the specified chat group member. Once the ownership is transferred, the former chat group owner becomes a regular member, and the new owner receives the ChatGroupEventListener#OnOwnerChanged callback.
The following code sample shows how to transfer the chat group ownership:
ChatClient.getInstance()
.groupManager.changeOwner(groupId, newOwner)
.then(() => {
console.log("change owner success.");
})
.catch((reason) => {
console.log("change owner fail.", reason);
});Add a chat group admin
Only the chat group owner can call addAdmin to add an admin. Once promoted to an admin, the new admin and the other chat group admins receive the ChatGroupEventListener#OnAdminAdded callback.
The following code sample shows how to add a chat group admin:
ChatClient.getInstance()
.groupManager.addAdmin(groupId, memberId)
.then(() => {
console.log("add admin success.");
})
.catch((reason) => {
console.log("add admin fail.", reason);
});Remove a chat group admin
Only the chat group owner can call removeAdmin to remove an admin. Once demoted to a regular member, the former admin and the other chat group admins receive the ChatGroupEventListener#OnAdminRemoved callback.
The following code sample shows how to remove a chat group admin:
ChatClient.getInstance()
.groupManager.removeAdmin(groupId, memberId)
.then(() => {
console.log("remove admin success.");
})
.catch((reason) => {
console.log("remove admin fail.", reason);
});Manage the chat group blocklist
Add a member to the chat group blocklist
Only the chat group owner and admins can call blockMembers to add the specified member to the chat group blocklist. Once added to the blocklist, this member receives the ChatGroupEventListener#onUserRemoved callback, while all the other members receive the ChatGroupEventListener#onMembersExited callback. After being added to blocklist, this user cannot send or receive messages in the chat group. They can no longer join the chat room until they are removed from the blocklist.
The following code sample shows how to add a member to the chat group blocklist:
ChatClient.getInstance()
.groupManager.blockMembers(groupId, members)
.then(() => {
console.log("block members success.");
})
.catch((reason) => {
console.log("block members fail.", reason);
});Remove a member from the chat group blocklist
Only the chat group owner and admins can call unblockMembers to remove the specified member from the chat group blocklist.
The following code sample shows how to remove a member from the chat group blocklist:
ChatClient.getInstance()
.groupManager.unblockMembers(groupId, members)
.then(() => {
console.log("unblock members success.");
})
.catch((reason) => {
console.log("unblock members fail.", reason);
});Retrieve the chat group blocklist
Only the chat group owner and admins can call fetchBlockListFromServer to retrieve the chat group blocklist.
The following code sample shows how to retrieve the chat group blocklist:
ChatClient.getInstance()
.groupManager.fetchBlockListFromServer(groupId, pageSize, pageNum)
.then((list) => {
console.log("get block members success: ", list);
})
.catch((reason) => {
console.log("get block members fail.", reason);
});Manage the chat group mute list
Add a member to the chat group mute list
Only the chat group owner and admins can call muteMembers to add the specified member to the chat group mute list. Once added to the mute list, this member and all the other chat group admins or owner receive the ChatGroupEventListener#onMuteListAdded callback. Once a chat group member is added to the chat group mute list, they can no longer send chat group messages, not even after being added to the chat group allow list.
The following code sample shows how to add a member to the chat group mute list:
// duration: The mute duration. If you pass `-1`, members are muted permanently.
ChatClient.getInstance()
.groupManager.muteMembers(groupId, members, duration)
.then(() => {
console.log("mute members success.");
})
.catch((reason) => {
console.log("mute members fail.", reason);
});Remove a member from the chat group mute list
Only the chat group owner and admins can call unMuteMembers to remove the specified member from the chat group mute list. Once removed from the chat group mute list, this member and all the other chat group admins or owner receive the ChatGroupEventListener#onMuteListRemoved callback.
The following code sample shows how to remove a member from the chat group mute list:
ChatClient.getInstance()
.groupManager.unMuteMembers(groupId, members)
.then(() => {
console.log("unMute members success.");
})
.catch((reason) => {
console.log("unMute members fail.", reason);
});Retrieve the chat group mute list
Only the chat group owner and admins can call fetchMuteListFromServer to retrieve the chat group mute list from the server.
The following code sample shows how to retrieve the chat group mute dictionary:
ChatClient.getInstance()
.groupManager.fetchMuteListFromServer(groupId, pageSize, pageNum)
.then((list) => {
console.log("get mute list success: ", list);
})
.catch((reason) => {
console.log("get mute list fail.", reason);
});Mute and unmute all the chat group members
Mute all the chat group members
Only the chat group owner and admins can call muteAllMembers to mute all the chat group members. All members in the group can receive the ChatGroupEventListener#onAllGroupMemberMuteStateChanged event.
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.
The following sample code shows how to mute all the chat group members:
ChatClient.getInstance()
.groupManager.muteAllMembers(groupId)
.then(() => {
console.log("mute all members success.");
})
.catch((reason) => {
console.log("mute all members fail.", reason);
});Unmute all the chat group members
Only the chat group owner and admins can call unMuteAllMembers to unmute all the chat group members. All members in the group can receive the ChatGroupEventListener#onAllGroupMemberMuteStateChanged event.
The following sample code shows how to unmute all the chat group members:
ChatClient.getInstance()
.groupManager.unMuteAllMembers(groupId)
.then(() => {
console.log("unMute all members success.");
})
.catch((reason) => {
console.log("unMute all members fail.", reason);
});Manage the chat group allow list
The chat group owner and admins are added to the chat group allow list by default.
Add a member to the chat group allow list
Only the chat group owner and admins can call addAllowList to add the specified member to 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, this member still cannot send messages in the group even after being added to the group allow list.
The following code sample shows how to add a member to the chat group allow list:
ChatClient.getInstance()
.groupManager.addAllowList(groupId, members)
.then(() => {
console.log("add white list success.");
})
.catch((reason) => {
console.log("add white list fail.", reason);
});Remove a member from the chat group allow list
Only the chat group owner and admins can call removeAllowList to remove the specified member from the chat group allow list.
The following code sample shows how to remove a member from the chat group allow list:
ChatClient.getInstance()
.groupManager.removeAllowList(groupId, members)
.then(() => {
console.log("remove white list success.");
})
.catch((reason) => {
console.log("remove white list fail.", reason);
});Check whether a user is added to the allow list
All chat group members can call isMemberInAllowListFromServer to check whether they are added to the chat group allow list.
The following code sample shows how to check whether a user is on the chat group allow list:
ChatClient.getInstance()
.groupManager.isMemberInAllowListFromServer(groupId)
.then((isMember) => {
console.log("is member success: ", isMember);
})
.catch((reason) => {
console.log("is member fail.", reason);
});Retrieve the chat group allow list
Only the chat group owner and admins can call fetchAllowListFromServer to retrieve the chat group allow list.
The following code sample shows how to retrieve the chat group allow list:
ChatClient.getInstance()
.groupManager.fetchAllowListFromServer(groupId)
.then(() => {
console.log("get white list success.");
})
.catch((reason) => {
console.log("get white list fail.", reason);
});Listen for chat group events
For details, see Chat Group Events.
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, IGroupManager, and IGroupManagerDelegate classes for chat group management, which allows you to implement the following features:
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.
Add a user to a chat group
The logic of adding a user to a chat group varies according to the GroupStyle and inviteNeedConfirm settings when creating the chat group. For details, see Create a Chat Group.
The following code sample shows how to call AddGroupMembers to add a user to a chat group:
SDKClient.Instance.GroupManager.AddGroupMembers(groupId, members, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));Remove a member from a chat group
Only the chat group owner and admins can call DeleteGroupMembers to remove one or more member from a chat group. Once removed from the chat group, the member receives the IGroupManagerDelegate#OnUserRemovedFromGroup callback, while all the other members receive the IGroupManagerDelegate#OnMembersExitedFromGroup callback. Users can join the chat group again after being removed.
The following code sample shows how to remove a member from a chat group:
SDKClient.Instance.GroupManager.DeleteGroupMembers(groupId, list, new CallBack (
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));Manage the chat group owner and admins
Transfer the chat group ownership
Only the chat group owner can call ChangeGroupOwner to transfer the ownership to the specified chat group member. Once the ownership is transferred, the former chat group owner becomes a regular member, and the new owner receives the IGroupManagerDelegate#OnOwnerChangedFromGroup callback.
The following code sample shows how to transfer the chat group ownership:
SDKClient.Instance.GroupManager.ChangeGroupOwner(groupId, newOwner, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));Add a chat group admin
Only the chat group owner can call AddGroupAdmin to add an admin. Once promoted to an admin, the new admin and the other chat group admins receive the IGroupManagerDelegate#OnAdminAddedFromGroup callback.
The following code sample shows how to add a chat group admin:
SDKClient.Instance.GroupManager.AddGroupAdmin(groupId, adminId, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));Remove a chat group admin
Only the chat group owner can call RemoveGroupAdmin to remove an admin. Once demoted to a regular member, the former admin and the other chat group admins receive the IGroupManagerDelegate#OnAdminRemovedFromGroup callback.
The following code sample shows how to remove a chat group admin:
SDKClient.Instance.GroupManager.RemoveGroupAdmin(groupId, adminId, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));Manage the chat group blocklist
Add a member to the chat group blocklist
Only the chat group owner and admins can call BlockGroupMembers to add the specified member to the chat group blocklist. Once added to the blocklist, this member receives the IGroupManagerDelegate#OnUserRemovedFromGroup callback, while all the other members receive the IGroupManagerDelegate#OnMembersExitedFromGroup. After being added to blocklist, this user cannot send or receive messages in the chat group. They can no longer join the chat group until they are removed from the blocklist.
The following code sample shows how to add a member to the chat group blocklist:
SDKClient.Instance.GroupManager.BlockGroupMembers(groupId, members, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));Remove a member from the chat group blocklist
Only the chat group owner and admins can call UnBlockGroupMembers to remove the specified member from the chat group blocklist.
The following code sample shows how to remove a member from the chat group blocklist:
SDKClient.Instance.GroupManager.UnBlockGroupMembers(groupId, members, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));Retrieve the chat group blocklist
Only the chat group owner and admins can call GetGroupBlockListFromServer to retrieve the chat group blocklist.
The following code sample shows how to retrieve the chat group blocklist:
SDKClient.Instance.GroupManager.GetGroupBlockListFromServer(groupId, pageNum, pageSize, callback: new ValueCallBack>(
onSuccess: (list) =>
{
},
onError: (code, desc) =>
{
}
));Manage the chat group mute list
Add a member to the chat group mute list
Only the chat group owner and admins can call MuteGroupMembers to add the specified member to the chat group mute list. Once added to the mute list, this member and all the other chat group admins or owner receive the IGroupManagerDelegate#OnMuteListAddedFromGroup callback. Once a chat group member is added to the chat group mute list, they can no longer send chat group messages, not even after being added to the chat group allow list.
The following code sample shows how to add a member to the chat group mute list:
// muteMilliseconds: The mute duration. If you pass `-1`, members are muted permanently.
SDKClient.Instance.GroupManager.MuteGroupMembers(groupId, members, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));Remove a member from the chat group mute list
Only the chat group owner and admins can call UnMuteGroupMembers to remove the specified member from the chat group mute list. Once removed from the chat group mute list, this member and all the other chat group admins or owner receive the IGroupManagerDelegate#OnMuteListRemovedFromGroup callback.
The following code sample shows how to remove a member from the chat group mute list:
SDKClient.Instance.GroupManager.UnMuteGroupMembers(groupId, members, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));Retrieve the chat group mute list
Only the chat group owner and admins can call GetGroupMuteListFromServer to retrieve the chat group mute list from the server.
The following code sample shows how to retrieve the chat group mute dictionary:
SDKClient.Instance.GroupManager.GetGroupMuteListFromServer(groupId, callback: new ValueCallBack>(
onSuccess: (list) => {
},
onError: (code, desc) =>
{
}
));Mute and unmute all the chat group members
Mute all the chat group members
Only the chat group owner and admins can call MuteGroupAllMembers to mute all the chat group members. All members in the group receive the IGroupManagerDelegate#OnAllMemberMuteChangedFromGroup event and 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 UnMuteGroupAllMembers method to unmute all members in the chat group.
The following sample code shows how to mute all the chat group members:
SDKClient.Instance.GroupManager.MuteGroupAllMembers(groupId, new CallBack(
onSuccess: () => {
},
onError: (code, desc) =>
{
}
));Unmute all the chat group members
Only the chat group owner and admins can call UnMuteGroupAllMembers to unmute all the chat group members. All members in the group receive the IGroupManagerDelegate#OnAllMemberMuteChangedFromGroup event.
The following sample code shows how to unmute all the chat group members:
SDKClient.Instance.GroupManager.UnMuteGroupAllMembers(groupId, new CallBack(
onSuccess: () => {
},
onError: (code, desc) =>
{
}
));Manage the chat group allow list
The chat group owner and admins are added to the chat group allow list by default.
Add a member to the chat group allow list
Only the chat group owner and admins can call AddGroupWhiteList to add the specified member to 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, this member still cannot send messages in the group even after being added to the group allow list.
The following code sample shows how to add a member to the chat group allow list:
SDKClient.Instance.GroupManager.AddGroupWhiteList(groupId, members, new CallBack(
onSuccess: () => {
},
onError: (code, desc) =>
{
}
));Remove a member from the chat group allow list
Only the chat group owner and admins can call RemoveGroupWhiteList to remove the specified member from the chat group allow list.
The following code sample shows how to remove a member from the chat group allow list:
SDKClient.Instance.GroupManager.RemoveGroupWhiteList(groupId, members, new CallBack(
onSuccess: () => {
},
onError: (code, desc) =>
{
}
));Check whether a user is added to the allow list
All chat group members can call checkIfInGroupWhiteList to check whether they are added to the chat group allow list.
The following code sample shows how to check whether a user is on the chat group allow list:
public void checkIfInGroupWhiteList(final String groupId, EMValueCallBack callBack)
SDKClient.Instance.GroupManager.CheckIfInGroupWhiteList(groupId, new ValueCallBack(
onSuccess: (ret) => {
},
onError: (code, desc)=> {
}
));Retrieve the chat group allow list
Only the chat group owner and admins can call GetGroupWhiteListFromServer to retrieve the chat group allow list.
The following code sample shows how to retrieve the chat group allow list:
SDKClient.Instance.GroupManager.GetGroupWhiteListFromServer(currentGroupId, callback: new ValueCallBack>(
onSuccess: (list) => {
},
onError: (code, desc) =>
{
}
));Listen for chat group events
For details, see Chat Group Events.
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, IGroupManager, and IGroupManagerDelegate classes for chat group management, which allows you to implement the following features:
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.
Add a user to a chat group
The logic of adding a user to a chat group varies according to the GroupStyle and inviteNeedConfirm settings when creating the chat group. For details, see Create a Chat Group.
The following code sample shows how to call AddGroupMembers to add a user to a chat group:
SDKClient.Instance.GroupManager.AddGroupMembers(groupId, members, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));Remove a member from a chat group
Only the chat group owner and admins can call DeleteGroupMembers to remove one or more members from a chat group. Once removed from the chat group, the member receives the IGroupManagerDelegate#OnUserRemovedFromGroup callback, while all the other members receive the IGroupManagerDelegate#OnMembersExitedFromGroup callback. Users can join the chat group again after being removed.
The following code sample shows how to remove a member from a chat group:
SDKClient.Instance.GroupManager.DeleteGroupMembers(groupId, list, new CallBack (
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));Manage the chat group owner and admins
Transfer the chat group ownership
Only the chat group owner can call ChangeGroupOwner to transfer the ownership to the specified chat group member. Once the ownership is transferred, the former chat group owner becomes a regular member, and the new owner receives the IGroupManagerDelegate#OnOwnerChangedFromGroup callback.
The following code sample shows how to transfer the chat group ownership:
SDKClient.Instance.GroupManager.ChangeGroupOwner(groupId, newOwner, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));Add a chat group admin
Only the chat group owner can call AddGroupAdmin to add an admin. Once promoted to an admin, the new admin and the other chat group admins receive the IGroupManagerDelegate#OnAdminAddedFromGroup callback.
The following code sample shows how to add a chat group admin:
SDKClient.Instance.GroupManager.AddGroupAdmin(groupId, adminId, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));Remove a chat group admin
Only the chat group owner can call RemoveGroupAdmin to remove an admin. Once demoted to a regular member, the former admin and the other chat group admins receive the IGroupManagerDelegate#OnAdminRemovedFromGroup callback.
The following code sample shows how to remove a chat group admin:
SDKClient.Instance.GroupManager.RemoveGroupAdmin(groupId, adminId, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));Manage the chat group blocklist
Add a member to the chat group blocklist
Only the chat group owner and admins can call BlockGroupMembers to add the specified member to the chat group blocklist. Once added to the blocklist, this member receives the IGroupManagerDelegate#OnUserRemovedFromGroup callback, while all the other members receive the IGroupManagerDelegate#OnMembersExitedFromGroup. After being added to blocklist, this user cannot send or receive messages in the chat group. They can no longer join the chat group until they are removed from the blocklist.
The following code sample shows how to add a member to the chat group blocklist:
SDKClient.Instance.GroupManager.BlockGroupMembers(groupId, members, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));Remove a member from the chat group blocklist
Only the chat group owner and admins can call UnBlockGroupMembers to remove the specified member from the chat group blocklist.
The following code sample shows how to remove a member from the chat group blocklist:
SDKClient.Instance.GroupManager.UnBlockGroupMembers(groupId, members, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));Retrieve the chat group blocklist
Only the chat group owner and admins can call GetGroupBlockListFromServer to retrieve the chat group blocklist.
The following code sample shows how to retrieve the chat group blocklist:
SDKClient.Instance.GroupManager.GetGroupBlockListFromServer(groupId, pageNum, pageSize, callback: new ValueCallBack>(
onSuccess: (list) =>
{
},
onError: (code, desc) =>
{
}
));Manage the chat group mute list
Add a member to the chat group mute list
Only the chat group owner and admins can call MuteGroupMembers to add the specified member to the chat group mute list. Once added to the mute list, this member and all the other chat group admins or owner receive the IGroupManagerDelegate#OnMuteListAddedFromGroup callback. Once a chat group member is added to the chat group mute list, they can no longer send chat group messages, not even after being added to the chat group allow list.
The following code sample shows how to add a member to the chat group mute list:
// muteMilliseconds: The mute duration. If you pass `-1`, members are muted permanently.
SDKClient.Instance.GroupManager.MuteGroupMembers(groupId, members, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));Remove a member from the chat group mute list
Only the chat group owner and admins can call UnMuteGroupMembers to remove the specified member from the chat group mute list. Once removed from the chat group mute list, this member and all the other chat group admins or owner receive the IGroupManagerDelegate#OnMuteListRemovedFromGroup callback.
The following code sample shows how to remove a member from the chat group mute list:
SDKClient.Instance.GroupManager.UnMuteGroupMembers(groupId, members, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));Retrieve the chat group mute list
Only the chat group owner and admins can call GetGroupMuteListFromServer to retrieve the chat group mute list from the server.
The following code sample shows how to retrieve the chat group mute dictionary:
SDKClient.Instance.GroupManager.GetGroupMuteListFromServer(groupId, callback: new ValueCallBack>(
onSuccess: (list) => {
},
onError: (code, desc) =>
{
}
));Mute and unmute all the chat group members
Mute all the chat group members
Only the chat group owner and admins can call MuteGroupAllMembers to mute all the chat group members. All members in the group can receive the IGroupManagerDelegate#OnAllMemberMuteChangedFromGroup event and 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 UnMuteGroupAllMembers method to unmute all members in the chat group.
The following sample code shows how to mute all the chat group members:
SDKClient.Instance.GroupManager.MuteGroupAllMembers(groupId, new CallBack(
onSuccess: () => {
},
onError: (code, desc) =>
{
}
));Unmute all the chat group members
Only the chat group owner and admins can call UnMuteGroupAllMembers to unmute all the chat group members. All members in the group can receive the IGroupManagerDelegate#OnAllMemberMuteChangedFromGroup event
The following sample code shows how to unmute all the chat group members:
SDKClient.Instance.GroupManager.UnMuteGroupAllMembers(groupId, new CallBack(
onSuccess: () => {
},
onError: (code, desc) =>
{
}
));Manage the chat group allow list
The chat group owner and admins are added to the chat group allow list by default.
Add a member to the chat group allow list
Only the chat group owner and admins can call AddGroupWhiteList to add the specified member to 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, this member still cannot send messages in the group even after being added to the group allow list.
The following code sample shows how to add a member to the chat group allow list:
SDKClient.Instance.GroupManager.AddGroupWhiteList(groupId, members, new CallBack(
onSuccess: () => {
},
onError: (code, desc) =>
{
}
));Remove a member from the chat group allow list
Only the chat group owner and admins can call RemoveGroupWhiteList to remove the specified member from the chat group allow list.
The following code sample shows how to remove a member from the chat group allow list:
SDKClient.Instance.GroupManager.RemoveGroupWhiteList(groupId, members, new CallBack(
onSuccess: () => {
},
onError: (code, desc) =>
{
}
));Check whether a user is added to the allow list
All chat group members can call checkIfInGroupWhiteList to check whether they are added to the chat group allow list.
The following code sample shows how to check whether a user is on the chat group allow list:
public void checkIfInGroupWhiteList(final String groupId, EMValueCallBack callBack)
SDKClient.Instance.GroupManager.CheckIfInGroupWhiteList(groupId, new ValueCallBack(
onSuccess: (ret) => {
},
onError: (code, desc)=> {
}
));Retrieve the chat group allow list
Only the chat group owner and admins can call GetGroupWhiteListFromServer to retrieve the chat group allow list.
The following code sample shows how to retrieve the chat group allow list:
SDKClient.Instance.GroupManager.GetGroupWhiteListFromServer(currentGroupId, callback: new ValueCallBack>(
onSuccess: (list) => {
},
onError: (code, desc) =>
{
}
));Listen for chat group events
For details, see Chat Group Events.
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 GroupManager and Group 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 blocklist 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. If the
allowinvitesparameter of the group type is set totrue, group members can also invite users to join the chat group. -
Implement chat group invitations. After the user is invited to join a group, the implementation logic varies based on the setting of the group option
inviteNeedConfirm:-
If
inviteNeedConfirmis set totrue, there are two cases:- The user calls
acceptGroupJoinRequestto accept the group invitation. After the user successfully joins the group, the inviter receives theacceptInvitecallback and all group members receive thememberPresencecallback. - The user calls
rejectGroupJoinRequestto decline the group invitation. In this case, the inviter receives therejectInvitecallback.
- The user calls
-
If
inviteNeedConfirmis set to false, the user is directly added to the chat group without confirming the group invitation. All group members receive thememberPresencecallback.
-
-
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 removed from the group, the member receives the
removeMembercallback and all the other group members receive thememberAbsencecallback.
Refer to the following sample code to add and remove a user:
// Group members can call inviteUsersToGroup to add users to a chat group.
const options = {
users: ["user1", "user2"],
groupId: "groupId",
};
chatClient.inviteUsersToGroup(options).then((res) => console.log(res));
// The chat group owner and chat group admins can call removeGroupMember to remove a group member from a chat group.
const options = {
groupId: "groupId",
username: "username",
};
chatClient.removeGroupMember(options).then((res) => console.log(res));
// The chat group owner and chat group admins can call removeGroupMembers to remove members from a chat group.
chatClient.removeGroupMembers({
groupId: "groupId",
users: ["user1", "user2"],
});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
changeOwnercallback. -
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 the
setAdmincallback. -
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 the
removeGroupAdmincallback.
Refer to the following sample code to manage chat group ownership and admin:
// The chat group owner can call changeGroupOwner to transfer ownership to the specified chat group member.
const options = {
groupId: "groupId",
newOwner: "username",
};
chatClient.changeGroupOwner(options).then((res) => console.log(res));
// The chat group owner can call setGroupAdmin to add admins.
const options = {
groupId: "groupId",
username: "user",
};
chatClient.setGroupAdmin(options).then((res) => console.log(res));
// The chat group owner can call removeGroupAdmin to remove admins.
const options = {
groupId: "groupId",
username: "user",
};
chatClient.removeGroupAdmin(options).then((res) => console.log(res));Manage the chat group blocklist
The chat group owner and chat group admins can add or remove the specified member to the chat group blocklist. Once a chat group member is added to the blocklist, 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 blocklist:
// The chat group owner and admins call blockGroupMember to add the specified member to the chat group blocklist.
const options = {
groupId: "groupId",
usernames: ["user1", "user2"],
};
chatClient.blockGroupMember(options).then((res) => console.log(res));
// The chat group owner and admins can call unblockGroupMembers to remove the specified member from the chat group blocklist.
// Once removed, the removed member can request to join the chat group again.
const options = {
groupId: "groupId",
username: ["user1", "user2"],
};
chatClient.unblockGroupMembers(options).then((res) => console.log(res));
// The chat group owner and admins can call getGroupBlocklist to retrieve the chat group blocklist.
const options = {
groupId: "groupId",
};
chatClient.getGroupBlocklist(options).then((res) => console.log(res));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:
// The chat group owner and admins can call muteGroupMember to add the specified member to the chat group mute list.
// The muted member and all the other chat group admins or owner receive the muteMember callback.
// muteDuration: The mute duration. If you pass `-1`, members are muted permanently.
const options = {
groupId: "groupId",
username: "user",
muteDuration: 886400000 // The mute duration. Unit: millisecond.
};
chatClient.muteGroupMember(options).then(res => console.log(res))
// The chat group owner and admins can call unmuteGroupMember to remove the specified user from the chat group mute list.
// The unmuted member and all the other chat group admins or owner receive the unmuteMember callback.
const options = {
groupId: "groupId",
username: "user"
};
chatClient.unmuteGroupMember(options).then(res => console.log(res))
// The chat group owner or admin can call getGroupMutelist to retrieve the chat group mute list.
const options = {
groupId: "groupId"
};
chatClient.getGroupMutelist(options).then(res => console.log(res))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 enableSendGroupMsg method to unmute all members in the chat group.
Refer to the following sample code to mute and unmute all the chat group members:
// The chat group owner or admin can call disableSendGroupMsg to mute all the chat group members.
// Once all the members are muted, these members receive the muteAllMembers callback.
const options = {
groupId: "groupId",
};
chatClient.disableSendGroupMsg(options).then((res) => console.log(res));
// The chat group owner or admin can call enableSendGroupMsg to unmute all the chat group members.
// Once all the members are unmuted, these members receive the unmuteAllMembers callback.
const options = {
groupId: "groupId",
};
chatClient.enableSendGroupMsg(options).then((res) => console.log(res));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 allow list.
Refer to the following sample code to manage the chat group allow list:
// The chat group owner or admin can call addUserToAllowlist to add the specified member to the chat group allow list.
// Once the member is added, all the other chat group admins or owner receive the addUsersToGroupAllowlist callback.
const options = {
groupId: "groupId",
users: ["user1", "user2"],
};
chatClient.addUsersToGroupAllowlist(options).then((res) => console.log(res));
// The chat group owner or admin can call removeAllowlistMember to remove the specified member from the chat group list.
// Once the member is removed, all the other chat group admins or owner receive the rmUserFromGroupWhiteList callback.
const options = {
groupId: "groupId",
userName: "user",
};
chatClient.removeAllowlistMember(options).then((res) => console.log(res));
// Chat group members can call isInGroupAllowlist to check whether they are in the chat group allow list.
const option = {
groupId: "groupId",
userName: "user",
};
chatClient.isInGroupAllowlist(option).then((res) => console.log(res));
// The chat group owner or admin can call getGroupAllowlist to retrieve the chat group allow list.
const options = {
groupId: "groupId",
};
chatClient.getGroupAllowlist(options).then((res) => console.log(res));Listen for chat group events
For details, see Chat Group Events.
