Group Member Management

Overview

Group member management includes pulling the member list, muting group members, removing group members, granting permissions, and transferring the group ownership, which can be implemented through the methods in the TencentImSDKPlugin.v2TIMManager.getGroupManager() core class.

Getting the Group Member List

Call getGroupMemberList to get the list of members in a specified group.
When the call is successful, the response returns a list of V2TimGroupMemberFullInfo. This object contains profile information for each group member, including the user ID (userID), group card (nameCard), avatar (faceUrl), nickname (nickName), join time (joinTime), online status (isOnline), and additional attributes.
Note:
The online status field (isOnline) is only available with Pro, Pro Plus or Enterprise edition.
Due to the large number of members in AVChatRoom, retrieving the complete member list is not supported. Pro, Pro Plus or Enterprise edition can retrieve up to the most recent 1,000 members who have joined. The backend updates the group member list every 40 seconds.
This feature must be enabled in the console.
Navigate to: My Applications > Chat > Configuration > Group Configuration > Group feature configuration > List of online audio-video group members.

Filter (filter)

When calling the getGroupMemberList API, you can specify filter to pull the list of the information of specified roles.
Filter
Type
GroupMemberFilterTypeEnum.V2TIM_GROUP_MEMBER_FILTER_ALL
Pull the list of the information of all the group members
GroupMemberFilterTypeEnum.V2TIM_GROUP_MEMBER_FILTER_OWNER
Pull the list of the information of the group owner
GroupMemberFilterTypeEnum.V2TIM_GROUP_MEMBER_FILTER_ADMIN
Pull the list of the information of the group admin
GroupMemberFilterTypeEnum.V2TIM_GROUP_MEMBER_FILTER_COMMON
Pull the information list of ordinary group members

Pulling by page (nextSeq)

In many cases, only the first page of the group member list, not the information of all the group members, needs to be displayed on the user UI. More group members need to be pulled only when the user clicks Next Page or pulls up the list page. In this case, you can use pulling by page.
Directions for pulling by page:
1. When you call getGroupMemberList for the first time, set nextSeq to 0 (indicating to pull the group member list from the beginning). Up to 50 group member objects can be pulled at a time.
2. After the group member list is pulled successfully for the first time, the V2TIMGroupMemberInfoResult callback of getGroupMemberList will contain nextSeq (field for the next pull):
If nextSeq is 0, all the group members have been pulled.
If nextSeq is greater than 0, there are more group members that can be pulled. This doesn't mean that the next page of the member list will be pulled immediately. In common communications software, a paged pull is often triggered by a swipe operation.
3. When the user continues to pull up the group member list, if there are more members that can be pulled, you can continue to call the getGroupMemberList API and pass in the nextSeq parameter (the value is from the V2TIMGroupMemberInfoResult object returned by the last pull) for the next pull.
4. Repeat [step 3] until nextSeq is 0.
Sample code:
{
...
String nextSeq = '0';
await getGroupMemberList(nextSeq);
...
}

Future<void> getGroupMemberList(String nextSeq) async {
// Use the `filter` parameter to specify only the profile of the group owner is to be pulled
final result = await TencentImSDKPlugin.v2TIMManager.getGroupManager().getGroupMemberList(
filter: GroupMemberFilterTypeEnum.V2TIM_GROUP_MEMBER_FILTER_ADMIN,
nextSeq: currentNextSeq,
groupID: 'your_group_id'
);
if (result.data?.nextSeq != '0') {
// Make another pull
await getGroupMemberList(result.data?.nextSeq);
}
}


Muting group members

Muting a specified group member

The group owner or admin can call muteGroupMember and set muteTime (in seconds) to mute a group member. If muteTime is set to 120, the member is muted for 120 seconds.
If a group member is muted, message sending will fail, and an error code will be reported. To unmute the member, set muteTime to 0.
The muting timestamp is stored in the muteUntil field of the group member information. Note that muteUntil indicates the end time for muting a group member.
After a group member is muted, all the group members (including the muted member) will receive the onMemberInfoChanged callback.
Note
The group owner can mute/unmute the admin and ordinary group members. The admin can mute/unmute ordinary group members.

Muting the entire group

The group owner or admin can also call the muteAllGroupMembers API to mute the entire group by setting the isMute field to true. The entire group can be muted for an unlimited period of time.
Muting all the group members will trigger the onAllGroupMembersMuted callback.
This notification is disabled by default. To enable it, you can log in to the Console to modify the relevant settings. Configuration path: Applications > Your App > Chat > Configuration > Group Configuration > Group system notification configuration > Notification of group profile change > Notification of muting all change.



Note:
Only the group owner can mute the admin.
Sample code:
// Mute the group member `userB` for 1 minute
final result = await TencentImSDKPlugin.v2TIMManager.getGroupManager().muteGroupMember(
groupID: 'your_group_id',
userID: 'userB',
seconds: 60
);

// Mute all members
final result = await TencentImSDKPlugin.v2TIMManager.getGroupManager().muteAllGroupMembers(
groupID: 'your_group_id',
isMute: true
);

TencentImSDKPlugin.v2TIMManager.addGroupListener(listener: V2TimGroupListener(
onMemberInfoChanged: (String groupID, List<V2TimGroupMemberChangeInfo> v2TIMGroupMemberChangeInfoList) {
// Muted group member callback
for (var memberChangeInfo in v2TIMGroupMemberChangeInfoList) {
// Muted user ID
String userID = memberChangeInfo.userID ?? '';
// Muted time
int muteTime = memberChangeInfo.muteTime ?? 0;
}
},
onAllGroupMembersMuted: (String groupID, bool isMute) {
// All-member mute callback
}
));


Removing Group Members

The group owner or admin can call the kickGroupMember API to remove a specified ordinary group member from the group.
After the ordinary group member is removed, all the members (including the removed member) will receive the onMemberKicked callback.
As an audio-video group (AVChatRoom) can be joined freely, there is no API for removing a group member from an audio-video group (AVChatRoom). You can use muteGroupMember to mute a specified member to implement similar controls.
Note:
Only the group owner can remove the admin from the group.
Sample code:
final result = await TencentImSDKPlugin.v2TIMManager.getGroupManager().kickGroupMember(
groupID: 'your_group_id',
memberList: ['target_user_id']
);

Setting an Admin

The group owner can call setGroupMemberRole to set a group member in a public group (Public) or meeting group (Meeting) as the admin.
An ordinary member set as the admin has the admin permission to perform the following operations:
Modify the basic group profile.
Remove an ordinary member from the group
Mute an ordinary member (prevent the member from speaking during a specified period of time)
Approve a request to join the group
For more information, see Group Member Roles.
After an ordinary member is set as the admin, all the members (including the ordinary member) will receive the onGrantAdministrator callback.
After the ordinary member is unset as the admin, all the members (including the ordinary member) will receive the onRevokeAdministrator callback.
Sample code:
final result = await TencentImSDKPlugin.v2TIMManager.getGroupManager().setGroupMemberRole(
groupID: 'your_group_id',
userID: 'target_user_id',
role: GroupMemberRoleTypeEnum.V2TIM_GROUP_MEMBER_ROLE_ADMIN
);

// Listen for the role change
TencentImSDKPlugin.v2TIMManager.addGroupListener(listener: V2TimGroupListener(
onGrantAdministrator: (String groupID, V2TimGroupMemberInfo info, List<V2TimGroupMemberInfo> infolist){},
onRevokeAdministrator: (String groupID, V2TimGroupMemberInfo info, List<V2TimGroupMemberInfo> infolist){},
));

Transferring Group Ownership

The group owner can call transferGroupOwner to transfer the group ownership to a group member.
After the group ownership is transferred, all the group members will receive the onGroupInfoChanged callback. Here, the type of V2TIMGroupChangeInfo is V2TIMGroupChangeInfo.V2TIM_GROUP_INFO_CHANGE_TYPE_OWNER, and the value is the UserID of the new group owner.
Sample code:
final result = await TencentImSDKPlugin.v2TIMManager.getGroupManager().transferGroupOwner(
groupID: 'your_group_id',
userID: 'target_user_id'
);

Getting the Number of Online Group Members

Call getGroupOnlineMemberCount to get the number of online group members.
Note:
1. This API is only supported in audio-video groups (AVChatRoom) before SDK 7.3 version.
2. You can call this API for all kinds of groups in SDK 7.3 and later versions.
Sample code:
final result = await TencentImSDKPlugin.v2TIMManager.getGroupManager().getGroupOnlineMemberCount(
groupID: 'your_group_id'
);