Chat groups enable real-time messaging among multiple users.
This page shows how to use the Agora Chat SDK to manage the members of a chat group in your app.
The Agora Chat SDK provides the Group
, IGroupManager
, and IGroupManagerDelegate
classes for chat group management, which allows you to implement the following features:
Before proceeding, ensure that you meet the following requirements:
This section describes how to call the APIs provided by the Agora Chat SDK to implement chat group features.
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) =>
{
}
));
Only the chat group owner and admins can call DeleteGroupMembers
to remove the specified member from a chat group. Once removed from the chat group, this member receives the IGroupManagerDelegate#OnUserRemovedFromGroup
callback, while all the other members receive the IGroupManagerDelegate#OnMemberExitedFromGroup
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) =>
{
}
));
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 all the other chat group members receive 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) =>
{
}
));
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) =>
{
}
));
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) =>
{
}
));
Only the chat group owner and admins can call BlockGroupMembers
to add the specified member to the chat group block list. Once added to the block list, this member receives the IGroupManagerDelegate#OnUserRemovedFromGroup
callback, while all the other members receive the IGroupManagerDelegate#OnMemberExitedFromGroup
. After being added to block list, 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 block list.
The following code sample shows how to add a member to the chat group block list:
SDKClient.Instance.GroupManager.BlockGroupMembers(groupId, members, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));
Only the chat group owner and admins can call UnBlockGroupMembers
to remove the specified member from the chat group block list.
The following code sample shows how to remove a member from the chat group block list:
SDKClient.Instance.GroupManager.UnBlockGroupMembers(groupId, members, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));
Only the chat group owner and admins can call GetGroupBlockListFromServer
to retrieve the chat group block list.
The following code sample shows how to retrieve the chat group block list:
SDKClient.Instance.GroupManager.GetGroupBlockListFromServer(groupId, pageNum, pageSize, handle: new ValueCallBack<List<string>>(
onSuccess: (list) =>
{
},
onError: (code, desc) =>
{
}
));
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:
SDKClient.Instance.GroupManager.MuteGroupMembers(groupId, members, new CallBack(
onSuccess: () =>
{
},
onError: (code, desc) =>
{
}
));
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) =>
{
}
));
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 list:
SDKClient.Instance.GroupManager.GetGroupMuteListFromServer(groupId, handle: new ValueCallBack<List<string>>(
onSuccess: (list) => {
},
onError: (code, desc) =>
{
}
));
Only the chat group owner and admins can call MuteGroupAllMembers
to mute 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.
The following sample code shows how to mute all the chat group members:
SDKClient.Instance.GroupManager.MuteGroupAllMembers(groupId, new CallBack(
onSuccess: () => {
},
onError: (code, desc) =>
{
}
));
Only the chat group owner and admins can call UnMuteGroupAllMembers
to unmute all the chat group members.
The following sample code shows how to unmute all the chat group members:
SDKClient.Instance.GroupManager.UnMuteGroupAllMembers(groupId, new CallBack(
onSuccess: () => {
},
onError: (code, desc) =>
{
}
));
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, adding this member to the allow list does not enable them to send messages. The mute list takes precedence.
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) =>
{
}
));
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) =>
{
}
));
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<Boolean> callBack)
SDKClient.Instance.GroupManager.CheckIfInGroupWhiteList(groupId, new ValueCallBack<bool>(
onSuccess: (ret) => {
},
onError: (code, desc)=> {
}
));
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, handle: new ValueCallBack<List<string>>(
onSuccess: (list) => {
},
onError: (code, desc) =>
{
}
));
For details, see Chat Group Events.