For permission groups, users can define permissions for groups as needed and configure different permissions and members for different permission groups, so that users can manage groups by permissions. Community groups can be managed by permission groups. Management of permission groups is more flexible than that of admins with fixed roles, making it suitable for communities with many members and topics.
Note:
The permission group feature is supported for version 7.8 and later.
The permission group V2TIMPermissionGroupInfo includes three elements: community permissions groupPermission, topic permissions topicPermission, and the group members who have these permissions. As shown in the figure above, users can configure different community permissions groupPermission and topic permissions topicPermission for different permission groups, and add different group members to achieve differentiated permission management. In addition, users can set default permissions defaultPermissions for communities and topics in community information V2TIMGroupInfo and topic information V2TIMTopicInfo. In this case, all group members have these default permissions. The rules for permission group management are as follows:
To enable the permission group feature, set enablePermissionGroup to true. In this case, the permissions of admins are disabled, making admins equivalent to ordinary group members. Conversely, setting it to false deactivates the permission group management feature and restores the permissions of admins.
Default community permissions defaultPermissions and default topic permissions defaultPermissions are automatically created in the community information V2TIMGroupInfo and topic information V2TIMTopicInfo, which are effective for all group members everyone (excluding the group owner).
Users can set community permissions groupPermission in permission groups V2TIMPermissionGroupInfo when creating permission groups, and then change the permissions later. Users can call the addTopicPermissionToPermissionGroup API to add topic permissions topicPermission to permission groups. The community permissions and topic permissions of a permission group are valid only for members in the group.
Permissions are represented by a 64-bit value, with each bit representing a permission. A bit value of 0 indicates that the permission is disabled, while a bit value of 1 indicates that the permission is enabled. The table of bits for community and topic permissions is as follows. For example, if the community permission value of a permission group is set to 5 (101 in binary mode), the members in the permission group have the permissions to modify group information and manage permission group information.
A group member's permission consists of the default everyone permission and the union of permissions from multiple permission groups that the member belongs to. That is, the group member has this permission when it is enabled anywhere.
Permission to recall others' messages in the current topic
Bit 6
V2TIM_TOPIC_PERMISSION_AT_ALL
Permission to send @all messages in the current topic
Examples
We use a scenario to introduce the permission group usage process. A sports community involves 3 topics, including [Important Notification], [Basketball], and [Football]. All members have the permission to retrieve historical messages sent before group joining in the [Important notification] topic, and the permission to send messages in the [Basketball] and [Football] topics. Member a has the permissions to modify community information, manage group members, and send messages in the [Important notification] topic, while members b and c have the permission to mute members in the [Basketball] and [Football] topics.
The process is as follows:
1. This is very important: In the community, set enablePermissionGroup to true to enable the permission group feature. This step can be the last step.
3. Set the everyone permissionsdefaultPermissions to 16 (10000 in binary mode) for the [Important Notification] topic, that is, V2TIM_TOPIC_PERMISSION_GET_HISTORY_MESSAGE. Set the everyone permissions defaultPermissions to 8 (1000 in binary mode) for the [Basketball] and [Football] topics, that is, V2TIM_TOPIC_PERMISSION_SEND_MESSAGE. In this case, all members can retrieve historical messages sent before group joining in the [Important notification] topic and send messages in the [Basketball] and [Football] topics.
4. Create a permission group named Community Management, and set the community permission groupPermission to 3 (11 in binary mode), which is the OR operation value specified by V2TIM_COMMUNITY_PERMISSION_MANAGE_GROUP_INFO | V2TIM_COMMUNITY_PERMISSION_MANAGE_GROUP_MEMBER for the permission. Add the messaging permissiontopicPermission in the [Important notification] topic, and set it to 8 (1000 in binary mode), that is V2TIM_TOPIC_PERMISSION_SEND_MESSAGE. After being added to the permission group, group member a will have permissions to modify community information, manage group members, and send messages in the [Important notification] topic.
5. Create a permission group named Topic Management, disable all community permissions, and set groupPermission to 0. Add the mute permissiontopicPermission in the [Basketball] and [Football] topics, and set it to 4 (100 in binary mode), that is V2TIM_TOPIC_PERMISSION_MUTE_MEMBER. After being added to this permission group, group members b and c will have permissions to mute members in the [Basketball] and [Football] topics.
Community Permission Management
Enabling/Disabling the Permission Group Feature
Groups can be managed by either admins or permission groups. When the permission group feature is enabled, the admin role is disabled, making admins equivalent to ordinary group members. When the permission group feature is disabled, the admin permissions are restored.
Set enablePermissionGroup (Java, Swift,Objective-C, C++) to enable or disable the permission group feature. When the feature is enabled, the admin role is disabled. When the feature is disabled, the admin permissions are restored.
The sample code is as follows:
Java
Swift
Objective-C
C++
V2TIMGroupInfo groupInfo =newV2TIMGroupInfo();
groupInfo.setGroupID("ID of the community for which the permission group feature needs to be enabled");
Group owners and members with permission to modify group information can set defaultPermissions (Java, Swift , Objective-C, C++) in V2TIMGroupInfo to change the default permissions of communities. These default permissions are effective for all group members everyone (excluding the group owner).
The sample code is as follows:
Java
Swift
Objective-C
C++
// Assume that it is required to allow all group members to send messages and retrieve historical messages sent before community joining in all topics by default, with other permissions disabled
long communityPermission =V2TIMPermissionGroupInfo.V2TIM_COMMUNITY_PERMISSION_SEND_MESSAGE |V2TIMPermissionGroupInfo.V2TIM_COMMUNITY_PERMISSION_GET_HISTORY_MESSAGE;
V2TIMGroupInfo groupInfo =newV2TIMGroupInfo();
groupInfo.setGroupID("ID of the community to be modified");
// Assume that it is required to allow all group members to send messages and retrieve historical messages sent before community joining in all topics by default, with other permissions disabled
// Assume that it is required to allow all group members to send messages and retrieve historical messages sent before community joining in all topics by default, with other permissions disabled
V2TIMGroupInfo info;
info.groupID ="ID of the community to be modified";
Group owners and members with permission to manage group information can call createPermissionGroupInCommunity (Java,Swift, Objective-C, C++) to create up to 20 permission groups by default.
v2TIMPermissionGroupInfo.setGroupID("ID of the community for which a permission group needs to be created");
v2TIMPermissionGroupInfo.setPermissionGroupID("Permission group ID, which can be left blank or custom");
v2TIMPermissionGroupInfo.setPermissionGroupName("Permission group name");
v2TIMPermissionGroupInfo.setCustomData("Custom character string of the permission group");
// Members of this permission group have the [permission to modify group information] and [permission to manage group members] long communityPermission =V2TIMPermissionGroupInfo.V2TIM_COMMUNITY_PERMISSION_MANAGE_GROUP_INFO |V2TIMPermissionGroupInfo.V2TIM_COMMUNITY_PERMISSION_MANAGE_GROUP_MEMBER;
Group owners and members with the permission to manage group information can call deletePermissionGroupFromCommunity (Java,Swift,Objective-C, C++) to delete permission groups.
The sample code is as follows:
Java
Swift
Objective-C
C++
List<String> deleteList =newArrayList<>();
deleteList.add("ID of permission group 1");
deleteList.add("ID of permission group 2");
V2TIMManager.getCommunityManager().deletePermissionGroupFromCommunity("ID of the community for which a permission group needs to be deleted", deleteList,newV2TIMValueCallback<List<V2TIMPermissionGroupOperationResult>>(){
V2TIMManager.shared.deletePermissionGroupFromCommunity(groupID:"groupID", permissionGroupIDList:["permissionGroupID1","permissionGroupID2"]){ resultList in
[deleteList addObject:@"ID of permission group 1"];
[deleteList addObject:@"ID of permission group 2"];
[[V2TIMManager sharedInstance] deletePermissionGroupFromCommunity:@"ID of the community for which a permission group needs to be deleted" permissionGroupIDList:deleteList succ:^(NSMutableArray<V2TIMPermissionGroupOperationResult *>*resultList){
// Deletion is successful, and resultList specifies the operation results for each permission group
V2TIMManager::GetInstance()->GetCommunityManager()->DeletePermissionGroupFromCommunity("ID of the community for which a permission group needs to be deleted", permissionGroupIDList, callback);
Group owners and members with the permission to manage group information can call modifyPermissionGroupInfoInCommunity (Java, Swift,Objective-C, C++) to change the name, permissions, and custom fields for a permission group.
v2TIMPermissionGroupInfo.setGroupID("ID of the community for which a permission group needs to be modified");// Required
v2TIMPermissionGroupInfo.setPermissionGroupID("ID of the permission group to be modified");// Required
v2TIMPermissionGroupInfo.setPermissionGroupName("Name of the permission group to be modified");
// Members in this permission group have the [permission to manage group information] and [permission to manage members in permission groups]
long communityPermission =V2TIMPermissionGroupInfo.V2TIM_COMMUNITY_PERMISSION_MANAGE_PERMISSION_GROUP_INFO |V2TIMPermissionGroupInfo.V2TIM_COMMUNITY_PERMISSION_MANAGE_PERMISSION_GROUP_MEMBER;
Group members can call getPermissionGroupListInCommunity (Java, Swift , Objective-C, C++) to access the permission group list. When the parameter permissionGroupIDList is not empty, you can access a specified permission group list. When permissionGroupIDList is empty, you can access all permission group lists.
// When permissionGroupIDList is set to a value, you can access a specified permission group list. When permissionGroupIDList is empty, you can access all permission group lists
permissionGroupIDList.add("ID of the permission group to access");
V2TIMManager.getCommunityManager().getPermissionGroupListInCommunity("ID of the community for which the permission group list needs to be accessed", permissionGroupIDList, newV2TIMValueCallback<List<V2TIMPermissionGroupInfoResult>>(){
// When permissionGroupIDList is set to a value, you can access a specified permission group list. When permissionGroupIDList is empty, you can access all permission group lists
[permissionGroupIDList addObject:@"The ID of the permission group to access"];
[[V2TIMManager sharedInstance] getPermissionGroupListInCommunity:@"ID of the community for which the permission group list needs to be accessed" permissionGroupIDList:permissionGroupIDList succ:^(NSMutableArray<V2TIMPermissionGroupInfoResult *>*resultList){
// The permission group list is successfully accessed
} fail:^(int code, NSString *desc){
// The permission group list fails to be accessed
}];
V2TIMStringVector permissionGroupIDList;
// When permissionGroupIDList is set to a value, you can access a specified permission group list. When permissionGroupIDList is empty, you can access all permission group lists
permissionGroupIDList.PushBack("The ID of the permission group to access");
V2TIMManager::GetInstance()->GetCommunityManager()->GetPermissionGroupListInCommunity("ID of the community for which the permission group list needs to be accessed", permissionGroupIDList, callback);
Accessing the List of Joined Permission Groups
Community members can call getJoinedPermissionGroupListInCommunity (Java, Swift, Objective-C, C++) to access the list of joined permission groups.
The sample code is as follows:
Java
Swift
Objective-C
C++
V2TIMManager.getCommunityManager().getJoinedPermissionGroupListInCommunity("ID of the community for which the permission group list needs to be accessed",newV2TIMValueCallback<List<V2TIMPermissionGroupInfoResult>>(){
[[V2TIMManager sharedInstance] getJoinedPermissionGroupListInCommunity:@"ID of the community for which the permission group list needs to be accessed"succ:^(NSMutableArray<V2TIMPermissionGroupInfoResult *>*resultList){
// The joined permission group is successfully accessed
} fail:^(int code, NSString *desc){
// The joined permission group fails to be accessed
// The joined permission group fails to be accessed
}
};
auto*callback = newTestCallBack;
V2TIMManager::GetInstance()->GetCommunityManager()->GetJoinedPermissionGroupListInCommunity("ID of the community for which the permission group list needs to be accessed", callback);
Adding Members to a Permission Group
Group owners and members with the permission to manage permission groups can call addCommunityMembersToPermissionGroup (Java, Swift,Objective-C, C++) to add up to 20 members to a permission group at a time.
The sample code is as follows:
Java
Swift
Objective-C
C++
List<String> memberList =newArrayList<>();
// Up to 20 members can be added at a time
memberList.add("userID of group member 1 to add");
memberList.add("userID of group member 2 to add");
V2TIMManager.getCommunityManager().addCommunityMembersToPermissionGroup("ID of the community for which members need to be added to a permission group","ID of the permission group where members need to be added", memberList,newV2TIMValueCallback<List<V2TIMPermissionGroupMemberOperationResult>>(){
// Notification for adding permission group members
}
});
V2TIMManager.shared.addCommunityMembersToPermissionGroup(groupID:"groupID", permissionGroupID:"permissionGroupID", memberList:["member1","member2"]){ resultList in
[memberList addObject:@"userID of group member 1 to add"];
[memberList addObject:@"userID of group member 2 to add"];
[[V2TIMManager sharedInstance] addCommunityMembersToPermissionGroup:@"ID of the community for which members need to be added to a permission group" permissionGroupID:@"ID of the permission group where members need to be added" memberList:memberList succ:^(NSMutableArray<V2TIMPermissionGroupMemberOperationResult *>*resultList){
V2TIMManager::GetInstance()->GetCommunityManager()->AddCommunityMembersToPermissionGroup("ID of the community for which members need to be added to a permission group","ID of the permission group where members need to be added", memberIDList, callback);
Group owners and members with the permission to manage permission group members can call removeCommunityMembersFromPermissionGroup (Java, Swift , Objective-C, C++) to remove members from a permission group.
The sample code is as follows:
Java
Swift
Objective-C
C++
List<String> memberList =newArrayList<>();
memberList.add("userID of group member 1 to remove");
memberList.add("userID of group member 2 to remove");
V2TIMManager.getCommunityManager().removeCommunityMembersFromPermissionGroup("ID of the community from which permission group members need to be removed","ID of the permission group from which members need to be removed", memberList,newV2TIMValueCallback<List<V2TIMPermissionGroupMemberOperationResult>>(){
// Notification of removing members from a permission group
}
});
V2TIMManager.shared.removeCommunityMembersFromPermissionGroup(groupID:"groupID", permissionGroupID:"permissionGroupID", memberList:["member1,member2"]){ resultList in
[memberList addObject:@"userID of group member 1 to remove"];
[memberList addObject:@"userID of group member 2 to remove"];
[[V2TIMManager sharedInstance] removeCommunityMembersFromPermissionGroup:@"ID of the community from which permission group members need to be removed" permissionGroupID:@"ID of the permission group from which members need to be removed" memberList:memberList succ:^(NSMutableArray<V2TIMPermissionGroupMemberOperationResult *>*resultList){
// Notification of removing members from a permission group
}
V2TIMStringVector memberIDList;
memberIDList.PushBack("userID of group member 1 to remove");
memberIDList.PushBack("userID of group member 2 to remove");classTestCallBack:public V2TIMValueCallback<V2TIMPermissionGroupMemberOperationResultVector>{
V2TIMManager::GetInstance()->GetCommunityManager()->RemoveCommunityMembersFromPermissionGroup("ID of the community from which permission group members need to be removed","ID of the permission group from which members need to be removed", memberIDList, callback);
Call getCommunityMemberListInPermissionGroup (Java, Swift ,Objective-C, C++) to access the member list in a permission group, where the parameter nextCursor indicates the continued pulling cursor. Fill in an empty character string for the first pulling, and fill in the return value from the last call output for continued pulling.
The sample code is as follows:
Java
Swift
Objective-C
C++
V2TIMManager.getCommunityManager().getCommunityMemberListInPermissionGroup("ID of the community for which the permission group members need to be accessed","ID of the permission group from which members need to be accessed","", newV2TIMValueCallback<V2TIMPermissionGroupMemberInfoResult>(){
// The member list in a permission group is successfully accessed, where result.getNextCursor() returns the continued pulling cursor. Fill in the return value when re-calling this API for continued pulling
}
@Override
publicvoidonError(int code,String desc){
// The member list in a permission group fails to be accessed
}
});
V2TIMManager.shared.getCommunityMemberListInPermissionGroup(groupID:"groupID", permissionGroupID:"permissionGroupID", nextCursor:""){ nextCursor, resultList in
[[V2TIMManager sharedInstance] getCommunityMemberListInPermissionGroup:@"ID of the community for which the permission group members need to be accessed"permissionGroupID:@"ID of the permission group from which members need to be accessed" nextCursor:@"" succ:^(NSString *nextCursor,NSMutableArray<V2TIMGroupMemberFullInfo *>*resultList){
// The member list in a permission group is successfully accessed, where nextCursor returns the continued pulling cursor. Fill in the return value when re-calling this API for continued pulling
} fail:^(int code, NSString *desc){
// The member list in a permission group fails to be accessed
// The member list in a permission group is successfully accessed, where value.nextCursor returns the continued pulling cursor. Fill in the return value when re-calling the API for continued pulling
// The member list in a permission group fails to be accessed
}
};
auto*callback =new TestCallBack;
V2TIMManager::GetInstance()->GetCommunityManager()->GetCommunityMemberListInPermissionGroup("ID of the community for which the permission group members need to be accessed","ID of the permission group from which members need to be accessed","", callback);
Topic Permission Management
Default Topic Permission
Group owners and members with the topic management permission can call setTopicInfo (Java, Swift ,Objective-C, C++) to modify the default permission of a topic. The default permission of the topic applies to all group members (excluding the group owner).
The sample code is as follows:
Java
Swift
Objective-C
C++
// Assume that it is required for all community members to have permissions to send messages in the current topic and retrieve historical messages sent before community joining in the topic
long topicPermission =V2TIMPermissionGroupInfo.V2TIM_TOPIC_PERMISSION_SEND_MESSAGE |V2TIMPermissionGroupInfo.V2TIM_TOPIC_PERMISSION_GET_HISTORY_MESSAGE;
V2TIMTopicInfo topicInfo =newV2TIMTopicInfo();
topicInfo.setTopicID("ID of the topic for which the default topic permission needs to be set");
// Assume that it is required for all community members to have permissions to send messages in the current topic and retrieve historical messages sent before community joining in the topic
// Assume that it is required for all community members to have permissions to send messages in the current topic and retrieve historical messages sent before community joining in the topic
V2TIMTopicInfo topicInfo;
topicInfo.topicID ="ID of the topic for which the default topic permission needs to be set";
Group owners and members with the permission to manage group information can call addTopicPermissionToPermissionGroup (Java,Swift,Objective-C, C++) to add topic permissions to a permission group. These permissions are effective for members of the permission group.
The sample code is as follows:
Java
Swift
Objective-C
C++
// Assume that it is required for members in the permission group to have the [permission to manage topic 1], [permission to mute members in topic 1], as well as the [permission to manage topic 2] and [permission to revoke others' messages in topic 2]
long topicPermission1 =V2TIMPermissionGroupInfo.V2TIM_TOPIC_PERMISSION_MANAGE_TOPIC |V2TIMPermissionGroupInfo.V2TIM_TOPIC_PERMISSION_MUTE_MEMBER;
long topicPermission2 =V2TIMPermissionGroupInfo.V2TIM_TOPIC_PERMISSION_MANAGE_TOPIC |V2TIMPermissionGroupInfo.V2TIM_TOPIC_PERMISSION_REVOKE_OTHER_MEMBER_MESSAGE;
topicPermissionMap.put("ID of topic 1",topicPermission1);
topicPermissionMap.put("ID of topic 2", topicPermission2);
V2TIMManager.getCommunityManager().addTopicPermissionToPermissionGroup("ID of the community for which topic permissions need to be added","ID of the permission group for which topic permissions need to be added",topicPermissionMap,newV2TIMValueCallback<List<V2TIMTopicOperationResult>>(){
// Assume that it is required for members in the permission group to have the [permission to manage topic 1], [permission to mute members in topic 1], as well as the [permission to manage topic 2] and [permission to revoke others' messages in topic 2]
let topicPermission1 =V2TIMTopicPermissionValue.V2TIM_TOPIC_PERMISSION_MANAGE_TOPIC.rawValue |V2TIMTopicPermissionValue.V2TIM_TOPIC_PERMISSION_MUTE_MEMBER.rawValue
let topicPermission2 =V2TIMTopicPermissionValue.V2TIM_TOPIC_PERMISSION_MANAGE_TOPIC.rawValue |V2TIMTopicPermissionValue.V2TIM_TOPIC_PERMISSION_REVOKE_OTHER_MEMBER_MESSAGE.rawValue
V2TIMManager.shared.addTopicPermissionToPermissionGroup(groupID:"ID of the community for which topic permissions need to be added", permissionGroupID:"ID of the permission group for which topic permissions need to be added", topicPermissionMap: topicPermissionMap, succ:{ resultList in
// Topic permissions are successfully added, with the parameter including the results of adding various topic permissions
// Assume that it is required for members in the permission group to have the [permission to manage topic 1], [permission to mute members in topic 1], as well as the [permission to manage topic 2] and [permission to revoke others' messages in topic 2]
[topicPermissionMap setValue:[NSNumber numberWithUnsignedLongLong:topicPermission1] forKey:@"ID of topic 1"];
[topicPermissionMap setValue:[NSNumber numberWithUnsignedLongLong:topicPermission2] forKey:@"ID of topic 2"];
[[V2TIMManager sharedInstance] addTopicPermissionToPermissionGroup:@"ID of the community for which topic permissions need to be added" permissionGroupID:@"ID of the permission group for which topic permissions need to be added" topicPermissionMap:topicPermissionMap succ:^(NSMutableArray<V2TIMTopicOperationResult *>*resultList){
// Topic permissions are successfully added, with the parameter including the results of adding various topic permissions
// Assume that it is required for members in the permission group to have the [permission to manage topic 1], [permission to mute members in topic 1], as well as the [permission to manage topic 2] and [permission to revoke others' messages in topic 2]
V2TIMStringToUint64Map topicPermissionMap;
topicPermissionMap.Insert("ID of topic 1",V2TIMTopicPermissionValue::V2TIM_TOPIC_PERMISSION_MANAGE_TOPIC |V2TIMTopicPermissionValue::V2TIM_TOPIC_PERMISSION_MUTE_MEMBER);
topicPermissionMap.Insert("ID of topic 2",V2TIMTopicPermissionValue::V2TIM_TOPIC_PERMISSION_MANAGE_TOPIC |V2TIMTopicPermissionValue::V2TIM_TOPIC_PERMISSION_REVOKE_OTHER_MEMBER_MESSAGE);
auto*callback =new TestCallBack;V2TIMManager::GetInstance()->GetCommunityManager()->AddTopicPermissionToPermissionGroup("ID of the community for which topic permissions need to be added","ID of the permission group for which topic permissions need to be added",topicPermissionMap, callback);
Deleting Topic Permissions from a Permission Group
Group owners and members with permission to manage permission group information can call deleteTopicPermissionFromPermissionGroup (Java,Swift, Objective-C, C++) to remove topic permissions from a permission group.
The sample code is as follows:
Java
Swift
Objective-C
C++
List<String> topicIDList =newArrayList<>();
topicIDList.add("ID of topic 1");
topicIDList.add("ID of topic 2");
V2TIMManager.getCommunityManager().deleteTopicPermissionFromPermissionGroup("ID of the community from which topic permissions need to be deleted","ID of the permission group from which topic permissions need to be deleted",topicIDList,newV2TIMValueCallback<List<V2TIMTopicOperationResult>>(){
[[V2TIMManager sharedInstance] deleteTopicPermissionFromPermissionGroup:@"ID of the community from which topic permissions need to be deleted" permissionGroupID:@"ID of the permission group from which topic permissions need to be deleted" topicIDList:deleteTopicIDList succ:^(NSMutableArray<V2TIMTopicOperationResult *>*resultList){
auto*callback =new TestCallBack;V2TIMManager::GetInstance()->GetCommunityManager()->DeleteTopicPermissionFromPermissionGroup("ID of the community from which topic permissions need to be deleted","ID of the permission group from which topic permissions need to be deleted", topicIDList, callback);
Group owners and members with the permission to manage permission group information can call modifyTopicPermissionInPermissionGroup (Java,Swift, Objective-C, C++) to modify the topic permissions of a permission group.
The sample code is as follows:
Java
Swift
Objective-C
C++
// Assume that it is required for members in a permission group to have the [permission to manage topics 1 and 2] and [permission to mute members in topics 1 and 2]
long topicPermission =V2TIMPermissionGroupInfo.V2TIM_TOPIC_PERMISSION_MANAGE_TOPIC |V2TIMPermissionGroupInfo.V2TIM_TOPIC_PERMISSION_MUTE_MEMBER;
topicPermissionMap.put("ID of topic 1",topicPermission);
topicPermissionMap.put("ID of topic 2", topicPermission);
V2TIMManager.getCommunityManager().modifyTopicPermissionInPermissionGroup("ID of the community where topic permissions need to be modified","ID of the permission group where topic permissions need to be modified",topicPermissionMap,newV2TIMValueCallback<List<V2TIMTopicOperationResult>>(){
// Assume that it is required for members in a permission group to have the [permission to manage topics 1 and 2] and [permission to mute members in topics 1 and 2]
var topicPermissionMap =Dictionary<String,NSNumber>()
let topicPermission =V2TIMTopicPermissionValue.V2TIM_TOPIC_PERMISSION_MANAGE_TOPIC.rawValue |V2TIMTopicPermissionValue.V2TIM_TOPIC_PERMISSION_MUTE_MEMBER.rawValue
topicPermissionMap["ID of topic 1"]=NSNumber(value: topicPermission)
topicPermissionMap["ID of topic 2"]=NSNumber(value: topicPermission)
V2TIMManager.shared.modifyTopicPermissionInPermissionGroup(groupID:"groupID", permissionGroupID:"permissionGroupID", topicPermissionMap: topicPermissionMap){ resultList in
resultList.forEach { item in
print("\(item.description)")
}
} fail:{ code, desc in
print("modifyTopicPermissionInPermissionGroup(modify or add topic permission) fail, \(code), \(desc)")
// Assume that it is required for members in a permission group to have the [permission to manage topics 1 and 2] and [permission to mute members in topics 1 and 2]
[topicPermissionMap setValue:[NSNumber numberWithUnsignedLongLong:topicPermission] forKey:@"ID of topic 1"];
[topicPermissionMap setValue:[NSNumber numberWithUnsignedLongLong:topicPermission] forKey:@"ID of topic 2"];
[[V2TIMManager sharedInstance] modifyTopicPermissionInPermissionGroup:@"ID of the community where topic permissions need to be modified" permissionGroupID:@"ID of the permission group where topic permissions need to be modified" topicPermissionMap:topicPermissionMap succ:^(NSMutableArray<V2TIMTopicOperationResult *>*resultList){
// Topic permissions are successfully modified for the permission group
} fail:^(int code, NSString *desc){
// Topic permissions fail to be modified for the permission group
// Assume that it is required for members in a permission group to have the [permission to manage topics 1 and 2] and [permission to mute members in topics 1 and 2]
V2TIMStringToUint64Map topicPermissionMap;
topicPermissionMap.Insert("ID of topic 1",V2TIMTopicPermissionValue::V2TIM_TOPIC_PERMISSION_MANAGE_TOPIC |V2TIMTopicPermissionValue::V2TIM_TOPIC_PERMISSION_MUTE_MEMBER);
topicPermissionMap.Insert("ID of topic 2",V2TIMTopicPermissionValue::V2TIM_TOPIC_PERMISSION_MANAGE_TOPIC |V2TIMTopicPermissionValue::V2TIM_TOPIC_PERMISSION_MUTE_MEMBER);
// Topic permissions fail to be modified for the permission group
}
};
auto*callback = newTestCallBack;
V2TIMManager::GetInstance()->GetCommunityManager()->ModifyTopicPermissionInPermissionGroup("ID of the community where topic permissions need to be modified","ID of the permission group where topic permissions need to be modified",topicPermissionMap, callback);
Group members can call getTopicPermissionInPermissionGroup (Java,Swift, Objective-C, C++) to access the list of topic permissions in a permission group. When topicIDList is set to a value, you can access certain topic permissions in a permission group. When topicIDList is empty, you can access all topic permissions in the permission group.
The sample code is as follows:
Java
Swift
Objective-C
C++
List<String> topicIDList =newArrayList<>();
// If topicIDList is set to a value, you can access a specific list of topic permissions. When topicIDList is empty, you can access all topic permissions lists
topicIDList.add("ID of topic 1");
topicIDList.add("ID of topic 2");
V2TIMManager.getCommunityManager().getTopicPermissionInPermissionGroup("ID of the community where topic permissions need to be accessed","ID of the permission group where topic permissions need to be accessed", topicIDList, newV2TIMValueCallback<List<V2TIMTopicPermissionResult>>(){
// If topicIDList is set to a value, you can access a specific list of topic permissions. When topicIDList is empty, you can access all topic permissions lists
[topicIDList addObject:@"ID of topic 1"];
[topicIDList addObject:@"ID of topic 2"];
[[V2TIMManager sharedInstance] getTopicPermissionInPermissionGroup:@"ID of the community where topic permissions need to be accessed" permissionGroupID:@"ID of the permission group where topic permissions need to be accessed"topicIDList:topicIDList succ:^(NSMutableArray<V2TIMTopicPermissionResult *>*resultList){
// Topic permissions of the permission group are successfully accessed
} fail:^(int code, NSString *desc){
// Topic permissions of the permission group fail to be accessed
}];
V2TIMStringVector topicIDList;
// If topicIDList is set to a value, you can access a specific list of topic permissions. When topicIDList is empty, you can access all topic permissions lists
// Topic permissions of the permission group fail to be accessed
}
};
auto*callback = newTestCallBack;
V2TIMManager::GetInstance()->GetCommunityManager()->GetTopicPermissionInPermissionGroup("ID of the community where topic permissions need to be accessed","ID of the permission group where topic permissions need to be accessed", topicIDList, callback);