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 ZIMGroupMemberInfoQueriedResult 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.
var groupID = '';
// If count exceeds 100, it will be treated as 100.
var config = { count: 10, nextFlag: 0 };

zim.queryGroupMemberList(groupID, config)
    .then(function ({ groupID, userList, nextFlag }) {
        // Query successful.
    })
    .catch(function (err) {
        // Query failed.
    });
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 ZIMGroupMemberInfoQueriedResult after the query succeeds.

SampleCode
//  Get the info of a specified group member.
var groupID = '';
var userID = '';
zim.queryGroupMemberInfo(userID, groupID)
    .then(function ({ groupID, userInfo }) {
        // Query successful.
    })
    .catch(function (err) {
        // Query failed.
    });
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 ZIMGroupMemberNicknameUpdatedResult 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. 
var groupID = '';
var forUserID = '';
var nickname = '';
zim.setGroupMemberNickname(nickname, forUserID, groupID)
    .then(function ({ groupID, forUserID, nickname }) {
        // Operation successful.
    })
    .catch(function (err) {
        // Operation failed.
    });

// Set up and listen for the callback groupMemberInfoUpdated.
zim.on('groupMemberInfoUpdated', function (zim, { groupID, userList, operatedInfo }) {
    console.log('groupMemberInfoUpdated', groupID, userList, operatedInfo);
});
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 ZIMGroupMemberRoleUpdatedResult .

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

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.
var groupID = '';
var forUserID = '';
var role = 2;
zim.setGroupMemberRole(role, forUserID, groupID)
    .then(function ({ groupID, forUserID, role }) {
        // Operation successful.
    })
    .catch(function (err) {
        // Operation failed.
    });

// Set up and listen for the callback groupMemberInfoUpdated.
zim.on('groupMemberInfoUpdated', function (zim, { groupID, userList, operatedInfo }) {
    console.log('groupMemberInfoUpdated', groupID, userList, operatedInfo);
});
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 groupMemberInfoUpdated after the group owner is changed.

SampleCode
// Change the group owner.
var groupID = '';
var toUserID = '';
zim.transferGroupOwner(toUserID, groupID)
    .then(function ({ groupID, toUserID }) {
        // Operation successful.
    })
    .catch(function (err) {
        // Operation failed.
    });

// Set up and listen for the callback groupMemberStateChanged.
zim.on('groupMemberStateChanged', function (zim, { groupID, state, event, userList, operatedInfo }) {
    console.log('groupMemberStateChanged', groupID, state, event, userList, operatedInfo);
});

// Set up and listen for the callback groupMemberInfoUpdated.
zim.on('groupMemberInfoUpdated', function (zim, { groupID, userList, operatedInfo }) {
    console.log('groupMemberInfoUpdated', groupID, userList, operatedInfo);
});
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 ZIMGroupMemberCountQueriedResult.

SampleCode
// Query the number of group members.
var groupID = '';
zim.queryGroupMemberCount(groupID)
    .then(function ({ groupID, count }) {
        // Operation successful.
    })
    .catch(function (err) {
        // Operation failed.
    });
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 ZIMGroupMembersSearchedResult interface.

SampleCode
// Search a group for members with "zego" in their name

var config = {
    count: 10, // number of search results
    nextFlag: 0,
    keywords: ['zego'], // Set the keywords to "zego", supports up to 5. When multiple keywords are set, the search results will only show local messages that contain all the keywords at the same time.
    isAlsoMatchGroupMemberNickname: true, // If a group member has a nickname that includes zego, the search results will include that group member.
};

zim.searchLocalGroupMembers('groupID', config)
    .then(function ({ groupID, userList, nextFlag }) {
        // Operation successful.
    })
    .catch(function (err) {
        // Operation failed.
    });
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 ZIMGroupMembersMutedResult .

Once a mute or unmute operation is successful, all group members will receive groupMemberInfoUpdated, 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
var isMute = true;
var userIDs = ["user_1", "user_2", "user_3"];
var groupID = "group_id";
var config = {
    duration: 30,  // Set the mute time to 30 seconds.
};

zim.muteGroupMembers(isMute, userIDs, groupID, config)
    .then(function ({ groupID, isMute, duration, mutedUserIDs, errorUserList }) {
        // Operation successful.
    })
    .catch(function (err) {
        // Operation failed.
    });
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 ZIMGroupMemberMutedListQueriedResult.

Untitled
 //  Query the member list of muted members in the group
var groupID = "group_id";
var config = {
    count: 100,
    nextFlag: 0,
}

zim.queryGroupMemberMutedList(groupID, config)
    .then(function ({ groupID, userList, nextFlag }) {
        // Operation successful.
    })
    .catch(function (err) {
        // Operation failed.
    });
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