logo
In-app Chat
SDK Error Codes
Powered Byspreading
On this page

Manage group members


ZEGOCLOUD's In-app Chat (the ZIM SDK) provides the capability of group member management, allowing you to query the group member list and group member info, change the group owner, and more.

Warning
  • Before you use the following features, you must join a group first. To join a group, refer to the Chapter Join a group of Manage groups.

Get group member list

To know who is in the current group and get the group member list after login, call the queryGroupMemberList method. A single call to the interface can obtain up to 100 members. If the passed count exceeds 100, it will be processed as 100.

You will receive a notification through the callback ZIMGroupMemberInfoQueriedCallback after the query succeeds.

Note

As of the current version, when this interface is called for the first time to pull the list of group members, the avatars of group members can be retrieved. If you call this interface again, you can get the avatar information of new users, but the avatar information of existing users will not be updated.

To get the latest avatars of group members, please call the interface queryGroupMemberInfo to query group member info.

SampleCode
// Get group member list.
ZIMGroupMemberQueryConfig config = new ZIMGroupMemberQueryConfig();
// count over 100 is treated as 100
config.count = 100;
config.nextFlag = 0;
zim.queryGroupMemberList(group_id, config, new ZIMGroupMemberListQueriedCallback() {
    @Override
    public void onGroupMemberListQueried(ArrayList<ZIMGroupMemberInfo> userList, int nextFlag, ZIMError errorInfo) {
    
    }
});
1
Copied!

Get group member info

To know the info of a specified member after joining a group, call the queryGroupMemberInfo method.

You will receive the specific info throught the callback ZIMGroupMemberInfoQueriedCallback after the query succeeds.

SampleCode
// Get group member info
zim.queryGroupMemberInfo(user_id, group_id, new ZIMGroupMemberListQueriedCallback() {
    @Override
    public void onGroupMemberListQueried(ArrayList<ZIMGroupMemberInfo> userList, int nextFlag, ZIMError errorInfo) {

    }
});
1
Copied!

Set an alias

To set an alias after joining a group, call the setGroupMemberNickname method.

Warning

The group owner can set the alias of all group members. But the group members can only set their own aliases.

You will receive a notification through the callback ZIMGroupMemberNicknameUpdatedCallback after the alias is set successfully.

SampleCode
// Set an alias. Note: The group owner can set the alias of all group members. But the group members can only set their own aliases. 
zim.setGroupMemberNickname(member_new_nick_name, user_id, group_id, new ZIMGroupMemberNicknameUpdatedCallback() {
    @Override
    public void onGroupMemberNicknameUpdated(ZIMError errorInfo) {

    }
});
1
Copied!

Set a role for a group member

For a group owner to set a role for a group member, call the setGroupMemberRole method. You can set the group member to a regular member or admin.

After the setting is successful, the group owner can receive the setting result through ZIMGroupMemberRoleUpdatedCallback .

Group members can receive notifications of user role changes through onGroupMemberInfoUpdated.

Description of group member roles and permissions

The ZIM SDK supports setting users as group owners, administrators, and regular members by default. In a group, the group owner has all client permissions and can perform all group functions. Administrators have most client permissions, while regular members have the fewest client permissions. The specific client permissions for each role are shown in the table below:

Client PermissionsGroup Owner
(corresponding enum value: 1)
Administrator
(corresponding enum value: 2)
Regular Member
(corresponding enum value: 3)
Modify group avatar, group name, group noticeSupportedSupportedSupported
Modify group attributes
Modify group member nicknameSupported, can be used for all group role usersSupported, can be used for all regular membersSupported, can only be used for oneself
Recall group member messages
Kick out membersNot supported
Mute individual group members
Mute specific group roles
Set group member rolesNot supported
Transfer group ownership
Dismiss the group
Mute all members
SampleCode
// The group owner sets ordinary member users as administrators.
zim.setGroupMemberRole(2, user_id, group_id, new ZIMGroupMemberRoleUpdatedCallback() {
    @Override
    public void onGroupMemberRoleUpdated(ZIMError errorInfo) {
// Obtain the result of setting the role of group members through errorInfo.code.
    }
});
1
Copied!

Transfer the group ownership

For a group owner to transfer the group ownership, call the transferGroupOwner method with the toUserID (the ID of the member you want to transfer the group ownership to).

Warning
  • Only the group owner has permission to change the group owner.
  • The member you want to transfer the group ownership to must be in the group; otherwise, the operation fails.

All group members will receive a notification through the callback onGroupMemberInfoUpdated after the group owner is changed.

SampleCode
// Change the group owner.
zim.transferGroupOwner(new_group_owner_id, group_id, new ZIMGroupOwnerTransferredCallback() {
    @Override
    public void onGroupOwnerTransferred(ZIMError errorInfo) {
        // Get the result of transferring group owner identity through errorInfo.code. 
    }
});
1
Copied!

Query the number of group members

To query the number of group members after logging in and joining a group, call the queryGroupMemberCount method.

You will receive the query results through the callback ZIMGroupMemberCountQueriedCallback.

SampleCode
// For an in-group member to query the number of group members.
zim.queryGroupMemberCount("GROUP_ID", new ZIMGroupMemberCountQueriedCallback() {
            @Override
            public void onGroupMemberCountQueried(String groupID, int count, ZIMError errorInfo) {
                // Get the number of group members.
            }
        });
1
Copied!

Search group members

After logging in to the ZIM SDK and joining a group, if you want to search for users within the group based on certain criteria, use the searchLocalGroupMembers interface. By providing the groupID、config、callback, you can search for group members that meet the specified conditions.

The search results will be returned through the ZIMGroupMembersSearchedCallback interface.

Untitled
// Search a group for members with "zego" in their name
ZIM zim = getZIM();
ZIMGroupMemberSearchConfig config = new ZIMGroupMemberSearchConfig();
config.count = 10;
config.nextFlag = nextFlag;
config.isAlsoMatchGroupMemberNickname = true; // If a group member's nickname contains zego, the search results will include that member
config.keywords.add("zego");
zim.searchLocalGroupMembers(conversationID, config, new ZIMGroupMembersSearchedCallback() {
    @Override
    public void onGroupMembersSearched(String groupID, ArrayList<ZIMGroupMemberInfo> userList, int nextFlag, ZIMError errorInfo) {
        // Developers can obtain group member information from userList
}});
1
Copied!

Set Mute status for group members

After logging into the ZIM SDK, you can mute or unmute specific members within the groups they manage. By calling the muteGroupMembers interface, you can modify the mute status of up to 100 group members in bulk. The mute duration can be permanent or up to a maximum of 604,800 seconds (7 days).

Note
  • The group owner can prohibit all group members, including themselves, from speaking.
  • If you need to increase the number of operations per request or extend the maximum mute duration, please contact ZEGOCLOUD technical support team.

After the settings are successfully applied, the operating user will receive notifications through ZIMGroupMembersMutedCallback .

Once a mute or unmute operation is successful, all group members will receive onGroupMemberInfoUpdated, which informs them about the members who are unable to speak in the group or have had their mute status lifted.

Note

If you want to mute certain group members , please refer Manage groups - Mute group.

Untitled
boolean isMute = true;

ArrayList<String> userIDList;
userIDList.add("user_1");
userIDList.add("user_3");
userIDList.add("user_2");

String groupID = "group_id";

ZIMGroupMemberMuteConfig config = new ZIMGroupMemberMuteConfig();
 // Mute duration: 30 seconds
config.duration = 30;

zim.muteGroupMembers(isMute, userIDList, groupID, config,new ZIMGroupMembersMutedCallback() {
    @Override
    public void onGroupMembersMuted(String groupID, boolean isMute, int duration, ArrayList<String> mutedMemberIDs, ArrayList<ZIMErrorUserInfo> errorUserList, ZIMError errorInfo) {
     //  Developers can retrieve relevant mute information from the callback parameters.
 }];
1
Copied!

Query Muted Members in a Group

After logging into the ZIM SDK, if you want to know the list of muted members in their group, you can use queryGroupMemberMutedList for querying.

Upon a successful query, the operating user can obtain specific information through ZIMGroupMemberMutedListQueriedCallback.

Untitled
 //  Query the member list of muted members in the group
ZIMGroupMemberMutedListQueryConfig config = new ZIMGroupMemberMutedListQueryConfig();
 // Get up to 100 members in one request
config.count = 100;
config.nextFlag = 0;
zim.queryGroupMemberMutedList(
    group_id, config, new ZIMGroupMemberMutedListQueriedCallback() {
    @Override
    public void onGroupMemberListQueried(String groupID, long nextFlag, ArrayList<ZIMGroupMemberInfo> userList, ZIMError errorInfo) {

    }
});
1
Copied!

Get the mute status of current group members

To actively retrieve the mute status of the current user in a group, please use any of the following methods:

Retrieve the mutedExpiredTime from the ZIMConversation object in the returned result, which indicates the mute duration in seconds.

The explanation of the mutedExpiredTime value is as follows:

  • When it is -1, it means the current user cannot speak in that group permanently.
  • When it is 0, it means the current user can speak in that group.
  • When it is 0, it means the current user can speak in that group.
Note

If the current user is both muted due to group role restrictions (refer to Manage groups - Mute or unmute group, and individually muted(refer to the section Set mute status for group members in this article), the value of mutedExpiredTime will be determined by taking the maximum value between the "group mute time" and the "individual mute time".

Previous

Manage group properties

Next

Send and receive messages