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 queryGroupMemberListByGroupID 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 queryGroupMemberInfoByGroupID to query group member info.

SampleCode
// Get group member list.
int myNextFlag = 0;
    ZIMGroupMemberQueryConfig *config = [[ZIMGroupMemberQueryConfig alloc] init];
// If count exceeds 100, it will be treated as 100.
    config.count = 20;
    config.nextFlag = myNextFlag;
    [zim queryGroupMemberListByGroupID:groupID config:config callback:^(NSArray<ZIMGroupMemberInfo *> * _Nonnull userList, unsigned int nextFlag, ZIMError * _Nonnull errorInfo) {
        //ave the anchor points of the group members for the next paging query.
            myNextFlag = nextFlag;
            // Implement the event callback for querying the group member list.
    }];
1
Copied!

Get group member info

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

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

SampleCode
// Get group member info.
[zim queryGroupMemberInfo:userID groupID:groupID callback:^(NSString * _Nonnull groupID, ZIMGroupMemberInfo * _Nonnull userInfo, ZIMError * _Nonnull errorInfo) {
    //Implement the event callback for querying the group member info.
}];
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:nickName forUserID:userID groupID:groupID callback:^(ZIMError * _Nonnull errorInfo) {
        //Implement the event callback for setting the alias here.
}];
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 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
// Group owner sets ordinary members as administrators.
[zim setGroupMemberRole:role forUserID:userID groupID:groupID callback:^(ZIMError * _Nonnull errorInfo) {
        //Implement business code after setting the role here.
}];
1
Copied!

Transfer the group ownership

For a group owner to transfer the group ownership, call the transferGroupOwnerToUserID 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.
[zim transferGroupOwnerToUserID:userID groupID:groupID callback:^(ZIMError * _Nonnull errorInfo) {
        //Implement the event callback for changing the group owner here.
}];
1
Copied!

Query the number of group members

To query the number of group members after logging in and joining a group, call the queryGroupMemberCountByGroupID 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 queryGroupMemberCountByGroupID:self.toGroupID callback:^(NSString * _Nonnull groupID, unsigned int count, ZIMError * _Nonnull errorInfo) {

}];
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 searchLocalGroupMembersByGroupID 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.

SampleCode
// Search for group members in a specific group whose names contain “zego”
ZIMGroupMemberSearchConfig *config = [[ZIMGroupMemberSearchConfig alloc] init];
config.count = 10;
config.isAlsoMatchGroupMemberNickname = true; // If the group member's nickname contains "zego", the search results will include that member.
config.keywords = @[@"zego"];
config.keywords = @[@"zego"];
[[ZIM getInstance] searchLocalGroupMembersByGroupID:@"groupID" config:config callback:^(NSString * _Nonnull groupID, NSArray<ZIMGroupMemberInfo *> * _Nonnull userList, unsigned int nextFlag, ZIMError * _Nonnull errorInfo) {
  // Developers can retrieve group member information from the 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|_blank 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 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
 ZIMGroupMemberMuteConfig *muteConfig = [[ZIMGroupMemberMuteConfig alloc] init];
 // Mute duration: 30 seconds
 muteConfig.duration = 30;
 [[ZIM getInstance] muteGroupMembers:YES userIDs:@[@"user_1",@"user_2",@"user_3"] groupID:@"group_id" config:muteConfig callback:^(NSString * _Nonnull groupID, BOOL isMute, int duration, NSArray<NSString *> * _Nonnull mutedMemberIDs, NSArray<ZIMErrorUserInfo *> * _Nonnull errorUserList, ZIMError * _Nonnull 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 queryGroupMemberMutedListByGroupID 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 = [[ZIMGroupMemberMutedListQueryConfig alloc] init];
 // Get up to 100 members in one request
 config.count = 100;
 config.nextFlag = 0;

 [[ZIM getInstance] queryGroupMemberMutedListByGroupID:@"groupID" config:config callback:^(NSString * _Nonnull groupID, unsigned long long nextFlag, NSArray<ZIMGroupMemberInfo *> * _Nonnull userList, ZIMError * _Nonnull errorInfo) {
    // Developers can retrieve information about the muted group members from the userList.
 }];
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