Manage room user attributes
This document is applicable to the following platforms of Unity framework: iOS, Android, macOS, and Windows.
Overview
The In-app Chat SDK provides the feature of configuring user attributes of users in a room, that is, customizing user attributes of users in a room. This feature applies to the following scenarios:
- Configure roles of room members, such as setting the room owner, administrator, participant, and participant level.
- Turn on/off the camera, turn on/off the microphone, mute/unmute a user, and enable/disable whiteboard sharing.
Implementation process
-
User attributes of up to 500 users can be configured in each room, and the user attributes are stored in
Key-Value
format. To increase the maximum number of user attributes that can be configured in each room, developers can contact ZEGOCLOUD technical support. -
The total length of user attribute
Key-Value
pairs of each user in a room cannot exceed 144 bytes, and the number ofKey-Value
pairs cannot exceed 30. In a singleKey-Value
pair, the key cannot exceed 8 bytes, and the value cannot exceed 64 bytes. To increase the maximum length of aKey-Value
pair, developers can contact ZEGOCLOUD technical support. -
After a room is destroyed, the configured customized user attributes are also deleted.
Configure user attributes
The operator and the user whose attributes are configured or modified must be users in the room.
Developers can call the setRoomMembersAttributes API to configure user attributes of users in a room. Configured user attributes are stored in Key-Value
format.
- When a key does not exist, configuring user attributes indicates adding a user attribute.
- When a key already exists, configuring user attributes indicates updating the value of an existing attribute.
title = "Sample code"
HashMap<String,String> attributes = new HashMap<>();
attributes.put("key1","value1");
ArrayList<String> userIDs = new ArrayList<>();
userIDs.add("userID1");
ZIMRoomMemberAttributesSetConfig setConfig = new ZIMRoomMemberAttributesSetConfig();
setConfig.isDeleteAfterOwnerLeft = true;
ZIM.getInstance().setRoomMembersAttributes(attributes, "roomID", userIDs, setConfig, new ZIMRoomMembersAttributesOperatedCallback() {
@Override
public void onRoomMembersAttributesOperated(String roomID, ArrayList<ZIMRoomMemberAttributesOperatedInfo> infos, ArrayList<String> errorUserList, ZIMError errorInfo) {
// The logic for returning the operation result.
}
});
HashMap<String,String> attributes = new HashMap<>();
attributes.put("key1","value1");
ArrayList<String> userIDs = new ArrayList<>();
userIDs.add("userID1");
ZIMRoomMemberAttributesSetConfig setConfig = new ZIMRoomMemberAttributesSetConfig();
setConfig.isDeleteAfterOwnerLeft = true;
ZIM.getInstance().setRoomMembersAttributes(attributes, "roomID", userIDs, setConfig, new ZIMRoomMembersAttributesOperatedCallback() {
@Override
public void onRoomMembersAttributesOperated(String roomID, ArrayList<ZIMRoomMemberAttributesOperatedInfo> infos, ArrayList<String> errorUserList, ZIMError errorInfo) {
// The logic for returning the operation result.
}
});
Sample code
ZIMRoomMemberAttributesSetConfig *setConfig = [[ZIMRoomMemberAttributesSetConfig alloc] init];
[[ZIM getInstance] setRoomMembersAttributes:@{@"key1":@"value1"} userIDs:@[@"user1",@"user2"] roomID:@"roomID" config:setConfig callback:^(NSString * _Nonnull roomID, NSArray<ZIMRoomMemberAttributesOperatedInfo *> * _Nonnull operatedInfos, NSArray<NSString *> * _Nonnull errorUserList, ZIMError * _Nonnull errorInfo) {
// The service logic after the configuration result is returned.
}];
ZIMRoomMemberAttributesSetConfig *setConfig = [[ZIMRoomMemberAttributesSetConfig alloc] init];
[[ZIM getInstance] setRoomMembersAttributes:@{@"key1":@"value1"} userIDs:@[@"user1",@"user2"] roomID:@"roomID" config:setConfig callback:^(NSString * _Nonnull roomID, NSArray<ZIMRoomMemberAttributesOperatedInfo *> * _Nonnull operatedInfos, NSArray<NSString *> * _Nonnull errorUserList, ZIMError * _Nonnull errorInfo) {
// The service logic after the configuration result is returned.
}];
Sample code
Dictionary<string, string> attributes = new Dictionary<string, string>();
attributes.Add("key1", "value1");
List<string> userIDs = new List<string>();
userIDs.Add("userID1");
ZIMRoomMemberAttributesSetConfig setConfig = new ZIMRoomMemberAttributesSetConfig();
setConfig.isDeleteAfterOwnerLeft = true;
ZIM.GetInstance().SetRoomMembersAttributes(attributes, userIDs, "roomID",
setConfig,
(string roomID, List<ZIMRoomMemberAttributesOperatedInfo> infos, List<string> errorUserList, ZIMError errorInfo) =>
{
// The service logic after the configuration result is returned.
}
);
Dictionary<string, string> attributes = new Dictionary<string, string>();
attributes.Add("key1", "value1");
List<string> userIDs = new List<string>();
userIDs.Add("userID1");
ZIMRoomMemberAttributesSetConfig setConfig = new ZIMRoomMemberAttributesSetConfig();
setConfig.isDeleteAfterOwnerLeft = true;
ZIM.GetInstance().SetRoomMembersAttributes(attributes, userIDs, "roomID",
setConfig,
(string roomID, List<ZIMRoomMemberAttributesOperatedInfo> infos, List<string> errorUserList, ZIMError errorInfo) =>
{
// The service logic after the configuration result is returned.
}
);
Sample code
Map<String, String> attributes = {"key1": "value1"};
List<String> userIDs = ["userID1"];
ZIM
.getInstance()
?.setRoomMembersAttributes(
attributes, userIDs, 'roomID', ZIMRoomMemberAttributesSetConfig())
.then((value) {
// The logic after the configuration is successful.
})
.catchError((onError) {
// The logic after the configuration fails.
});
Map<String, String> attributes = {"key1": "value1"};
List<String> userIDs = ["userID1"];
ZIM
.getInstance()
?.setRoomMembersAttributes(
attributes, userIDs, 'roomID', ZIMRoomMemberAttributesSetConfig())
.then((value) {
// The logic after the configuration is successful.
})
.catchError((onError) {
// The logic after the configuration fails.
});
Sample code
const config: ZIMRoomMemberAttributesSetConfig = {
isDeleteAfterOwnerLeft: false
};
zim.setRoomMembersAttributes({'key1': 'value1'}, ['user1', 'user2'], 'roomID', config).then(res => {
// The service logic after the configuration result is returned.
});
const config: ZIMRoomMemberAttributesSetConfig = {
isDeleteAfterOwnerLeft: false
};
zim.setRoomMembersAttributes({'key1': 'value1'}, ['user1', 'user2'], 'roomID', config).then(res => {
// The service logic after the configuration result is returned.
});
Sample code
std::unordered_map<std::string, std::string> attributes;
attributes.emplace(std::string("key1"),std::string("value1"));
std::vector<std::string> userIDs;
userIDs.push_back(std::string("userID1"));
ZIMRoomMemberAttributesSetConfig setConfig;
setConfig.isDeleteAfterOwnerLeft = true;
ZIM::getInstance()->setRoomMembersAttributes(attributes, userIDs, std::string("roomID"), setConfig, [=](const std::string &roomID, const std::vector<ZIMRoomMemberAttributesOperatedInfo> &infos, const std::vector<std::string> &errorUsers, const ZIMError &errorInfo){
// Fill in the logic for handling the operation result here
});
std::unordered_map<std::string, std::string> attributes;
attributes.emplace(std::string("key1"),std::string("value1"));
std::vector<std::string> userIDs;
userIDs.push_back(std::string("userID1"));
ZIMRoomMemberAttributesSetConfig setConfig;
setConfig.isDeleteAfterOwnerLeft = true;
ZIM::getInstance()->setRoomMembersAttributes(attributes, userIDs, std::string("roomID"), setConfig, [=](const std::string &roomID, const std::vector<ZIMRoomMemberAttributesOperatedInfo> &infos, const std::vector<std::string> &errorUsers, const ZIMError &errorInfo){
// Fill in the logic for handling the operation result here
});
Query user attributes of some users
Users in a room can call the queryRoomMembersAttributes API to query the user attributes of some users in the room.
Sample code
ArrayList<String> userIDs = new ArrayList<>();
userIDs.add("userID1");
ZIM.getInstance().queryRoomMembersAttributes(userIDs, "roomID", new ZIMRoomMembersAttributesQueriedCallback() {
@Override
public void onRoomMembersAttributesQueried(String roomID, ArrayList<ZIMRoomMemberAttributesInfo> infos, ZIMError errorInfo) {
// The logic for returning the query result.
}
});
ArrayList<String> userIDs = new ArrayList<>();
userIDs.add("userID1");
ZIM.getInstance().queryRoomMembersAttributes(userIDs, "roomID", new ZIMRoomMembersAttributesQueriedCallback() {
@Override
public void onRoomMembersAttributesQueried(String roomID, ArrayList<ZIMRoomMemberAttributesInfo> infos, ZIMError errorInfo) {
// The logic for returning the query result.
}
});
Sample code
[[ZIM getInstance] queryRoomMembersAttributesByUserIDs:@[@"userID1",@"userID2"] roomID:@"roomID" callback:^(NSString * _Nonnull roomID, NSArray<ZIMRoomMemberAttributesInfo *> * _Nonnull infos, ZIMError * _Nonnull errorInfo) {
// The service logic after the query result is returned.
}];
[[ZIM getInstance] queryRoomMembersAttributesByUserIDs:@[@"userID1",@"userID2"] roomID:@"roomID" callback:^(NSString * _Nonnull roomID, NSArray<ZIMRoomMemberAttributesInfo *> * _Nonnull infos, ZIMError * _Nonnull errorInfo) {
// The service logic after the query result is returned.
}];
Sample code
List<string> userIDs = new List<string>();
userIDs.Add("userID1");
ZIM.GetInstance().QueryRoomMembersAttributes(userIDs, "roomID", (string roomID, List<ZIMRoomMemberAttributesInfo> infos, ZIMError errorInfo) =>
{
//The service logic after the query result is returned.
}
);
List<string> userIDs = new List<string>();
userIDs.Add("userID1");
ZIM.GetInstance().QueryRoomMembersAttributes(userIDs, "roomID", (string roomID, List<ZIMRoomMemberAttributesInfo> infos, ZIMError errorInfo) =>
{
//The service logic after the query result is returned.
}
);
Sample code
Map<String, String> attributes = {"key1": "value1"};
List<String> userIDs = ["userID1"];
ZIM
.getInstance()
?.queryRoomMembersAttributes(userIDs, 'roomID')
.then((value) {
// The logic after the configuration is successful.
})
.catchError((onError) {
// The logic after the configuration fails.
});
Map<String, String> attributes = {"key1": "value1"};
List<String> userIDs = ["userID1"];
ZIM
.getInstance()
?.queryRoomMembersAttributes(userIDs, 'roomID')
.then((value) {
// The logic after the configuration is successful.
})
.catchError((onError) {
// The logic after the configuration fails.
});
Sample code
zim.queryRoomMembersAttributes['user1', 'user2'], 'roomID').then(res => {
// The service logic after the query result is returned.
});
zim.queryRoomMembersAttributes['user1', 'user2'], 'roomID').then(res => {
// The service logic after the query result is returned.
});
Sample code
std::vector<std::string> userIDs;
userIDs.push_back(std::string("userID1"));
ZIM::getInstance()->queryRoomMembersAttributes(userIDs, std::string("roomID"), [=](const std::string &roomID, const std::vector<ZIMRoomMemberAttributesInfo> &infos, const ZIMError &errorInfo){
// Fill in the logic for handling the query result here
});
std::vector<std::string> userIDs;
userIDs.push_back(std::string("userID1"));
ZIM::getInstance()->queryRoomMembersAttributes(userIDs, std::string("roomID"), [=](const std::string &roomID, const std::vector<ZIMRoomMemberAttributesInfo> &infos, const ZIMError &errorInfo){
// Fill in the logic for handling the query result here
});
Query user attributes of all users
Users in a room can call the queryRoomMemberAttributesList API to query the user attributes of all users in the room.
Sample code
ZIMRoomMemberAttributesQueryConfig queryConfig = new ZIMRoomMemberAttributesQueryConfig();
queryConfig.count = 100;
queryConfig.nextFlag = "";
ZIM.getInstance().queryRoomMemberAttributesList(
"roomID", queryConfig, new ZIMRoomMemberAttributesListQueriedCallback() {
@Override
public void onRoomMemberAttributesListQueried(String roomID, ArrayList<ZIMRoomMemberAttributesInfo> infos, String nextFlag,ZIMError errorInfo) {
if (nextFlag == "") {
// User attributes of all users in the room are queried.
}else{
// Continue to query the next page.
}
}
});
ZIMRoomMemberAttributesQueryConfig queryConfig = new ZIMRoomMemberAttributesQueryConfig();
queryConfig.count = 100;
queryConfig.nextFlag = "";
ZIM.getInstance().queryRoomMemberAttributesList(
"roomID", queryConfig, new ZIMRoomMemberAttributesListQueriedCallback() {
@Override
public void onRoomMemberAttributesListQueried(String roomID, ArrayList<ZIMRoomMemberAttributesInfo> infos, String nextFlag,ZIMError errorInfo) {
if (nextFlag == "") {
// User attributes of all users in the room are queried.
}else{
// Continue to query the next page.
}
}
});
Sample code
ZIMRoomMemberAttributesQueryConfig *queryConfig = [[ZIMRoomMemberAttributesQueryConfig alloc] init];
queryConfig.count = 100;
[[ZIM getInstance] queryRoomMemberAttributesListByRoomID:@"roomID" config:queryConfig callback:^(NSString * _Nonnull roomID, NSArray<ZIMRoomMemberAttributesInfo *> * _Nonnull infos, NSString * _Nonnull nextFlag, ZIMError * _Nonnull errorInfo) {
// The service logic after the query result is returned.
}];
ZIMRoomMemberAttributesQueryConfig *queryConfig = [[ZIMRoomMemberAttributesQueryConfig alloc] init];
queryConfig.count = 100;
[[ZIM getInstance] queryRoomMemberAttributesListByRoomID:@"roomID" config:queryConfig callback:^(NSString * _Nonnull roomID, NSArray<ZIMRoomMemberAttributesInfo *> * _Nonnull infos, NSString * _Nonnull nextFlag, ZIMError * _Nonnull errorInfo) {
// The service logic after the query result is returned.
}];
Sample code
ZIMRoomMemberAttributesQueryConfig *queryConfig = [[ZIMRoomMemberAttributesQueryConfig alloc] init];
queryConfig.count = 100;
[[ZIM getInstance] queryRoomMemberAttributesListByRoomID:@"roomID" config:queryConfig callback:^(NSString * _Nonnull roomID, NSArray<ZIMRoomMemberAttributesInfo *> * _Nonnull infos, NSString * _Nonnull nextFlag, ZIMError * _Nonnull errorInfo) {
// The service logic after the query result is returned.
}];
ZIMRoomMemberAttributesQueryConfig *queryConfig = [[ZIMRoomMemberAttributesQueryConfig alloc] init];
queryConfig.count = 100;
[[ZIM getInstance] queryRoomMemberAttributesListByRoomID:@"roomID" config:queryConfig callback:^(NSString * _Nonnull roomID, NSArray<ZIMRoomMemberAttributesInfo *> * _Nonnull infos, NSString * _Nonnull nextFlag, ZIMError * _Nonnull errorInfo) {
// The service logic after the query result is returned.
}];
Sample code
ZIMRoomMemberAttributesQueryConfig queryConfig = new ZIMRoomMemberAttributesQueryConfig();
queryConfig.count = 100;
queryConfig.nextFlag = "";
ZIM.GetInstance().QueryRoomMemberAttributesList(
"roomID", queryConfig, (string roomID, List<ZIMRoomMemberAttributesInfo> infos, string nextFlag, ZIMError errorInfo) =>
{
if (nextFlag == "")
{
// All user room user attributes have been queried
}
else
{
// Continue querying the next page.
}
}
);
ZIMRoomMemberAttributesQueryConfig queryConfig = new ZIMRoomMemberAttributesQueryConfig();
queryConfig.count = 100;
queryConfig.nextFlag = "";
ZIM.GetInstance().QueryRoomMemberAttributesList(
"roomID", queryConfig, (string roomID, List<ZIMRoomMemberAttributesInfo> infos, string nextFlag, ZIMError errorInfo) =>
{
if (nextFlag == "")
{
// All user room user attributes have been queried
}
else
{
// Continue querying the next page.
}
}
);
Sample code
ZIM
.getInstance()
?.queryRoomMemberAttributesList(
'roomID', ZIMRoomMemberAttributesQueryConfig())
.then((value) {
// The logic after the configuration is successful.
})
.catchError((onError) {
// The logic after the configuration fails.
});
ZIM
.getInstance()
?.queryRoomMemberAttributesList(
'roomID', ZIMRoomMemberAttributesQueryConfig())
.then((value) {
// The logic after the configuration is successful.
})
.catchError((onError) {
// The logic after the configuration fails.
});
typescript
const config: ZIMRoomMemberAttributesQueryConfig = {
nextFlag: '',
count: 100
}
zim.queryRoomMemberAttributesList('roomID', config).then(res => {
// The service logic after the query result is returned.
});
const config: ZIMRoomMemberAttributesQueryConfig = {
nextFlag: '',
count: 100
}
zim.queryRoomMemberAttributesList('roomID', config).then(res => {
// The service logic after the query result is returned.
});
Sample code
ZIMRoomMemberAttributesQueryConfig queryConfig = ZIMRoomMemberAttributesQueryConfig(std::string(""), 100);
ZIM::getInstance()->queryRoomMemberAttributesList(std::string("roomID"), queryConfig, [=](const std::string &roomID, const std::vector<ZIMRoomMemberAttributesInfo> &infos,const std::string &nextFlag, const ZIMError &errorInfo){
if (nextFlag == "") {
// All room member attributes for all users have been queried
}else{
// Continue querying the next page
}
});
ZIMRoomMemberAttributesQueryConfig queryConfig = ZIMRoomMemberAttributesQueryConfig(std::string(""), 100);
ZIM::getInstance()->queryRoomMemberAttributesList(std::string("roomID"), queryConfig, [=](const std::string &roomID, const std::vector<ZIMRoomMemberAttributesInfo> &infos,const std::string &nextFlag, const ZIMError &errorInfo){
if (nextFlag == "") {
// All room member attributes for all users have been queried
}else{
// Continue querying the next page
}
});
User attribute change notification
When user attributes of members in a room are changed, you can register the OnRoomMemberAttributesUpdated
callback API to listen for user attribute change notifications of members in the room.
When user attributes of members in a room are changed, developers can register the onRoomMemberAttributesUpdated method of the on callback API to listen for user attribute change notifications of members in the room.
public void onRoomMemberAttributesUpdated(ZIM zim,
ArrayList<ZIMRoomMemberAttributesUpdateInfo> infos,
ZIMRoomOperatedInfo operatedInfo, String roomID) {
//The service logic after user attributes of members in a room are changed.
}
public void onRoomMemberAttributesUpdated(ZIM zim,
ArrayList<ZIMRoomMemberAttributesUpdateInfo> infos,
ZIMRoomOperatedInfo operatedInfo, String roomID) {
//The service logic after user attributes of members in a room are changed.
}
- (void)zim:(ZIM *)zim
roomMemberAttributesUpdated:(NSArray<ZIMRoomMemberAttributesUpdateInfo *> *)updateInfo
operatedUserInfo:(ZIMRoomOperatedInfo *)operatedInfo
roomID:(NSString *)roomID{
//The service logic after user attributes of members in a room are changed.
}
- (void)zim:(ZIM *)zim
roomMemberAttributesUpdated:(NSArray<ZIMRoomMemberAttributesUpdateInfo *> *)updateInfo
operatedUserInfo:(ZIMRoomOperatedInfo *)operatedInfo
roomID:(NSString *)roomID{
//The service logic after user attributes of members in a room are changed.
}
- (void)zim:(ZIM *)zim
roomMemberAttributesUpdated:(NSArray<ZIMRoomMemberAttributesUpdateInfo *> *)updateInfo
operatedUserInfo:(ZIMRoomOperatedInfo *)operatedInfo
roomID:(NSString *)roomID{
//The service logic after user attributes of members in a room are changed.
}
- (void)zim:(ZIM *)zim
roomMemberAttributesUpdated:(NSArray<ZIMRoomMemberAttributesUpdateInfo *> *)updateInfo
operatedUserInfo:(ZIMRoomOperatedInfo *)operatedInfo
roomID:(NSString *)roomID{
//The service logic after user attributes of members in a room are changed.
}
ZIM.GetInstance().onRoomMemberAttributesUpdated = (
ZIM zim, List<ZIMRoomMemberAttributesUpdateInfo> infos,
ZIMRoomOperatedInfo operatedInfo, string roomID) =>
{
// The service logic after user attributes of members in a room are changed.
};
ZIM.GetInstance().onRoomMemberAttributesUpdated = (
ZIM zim, List<ZIMRoomMemberAttributesUpdateInfo> infos,
ZIMRoomOperatedInfo operatedInfo, string roomID) =>
{
// The service logic after user attributes of members in a room are changed.
};
ZIMEventHandler.onRoomMemberAttributesUpdated = (
ZIM zim,List<ZIMRoomMemberAttributesUpdateInfo> infos,ZIMRoomOperatedInfo operatedInfo, String roomID){
//The service logic after user attributes of members in a room are changed.
};
ZIMEventHandler.onRoomMemberAttributesUpdated = (
ZIM zim,List<ZIMRoomMemberAttributesUpdateInfo> infos,ZIMRoomOperatedInfo operatedInfo, String roomID){
//The service logic after user attributes of members in a room are changed.
};
zim.on('roomMemberAttributesUpdated', (zim, data) => {
//The service logic after user attributes of members in a room are changed.
});
zim.on('roomMemberAttributesUpdated', (zim, data) => {
//The service logic after user attributes of members in a room are changed.
});
void onRoomMemberAttributesUpdated(ZIM * /*zim*/, const std::vector<ZIMRoomMemberAttributesUpdateInfo> & /*infos*/,ZIMRoomOperatedInfo /*operatedInfo*/, const std::string & /*roomID*/) override{
// Write the business logic after the room member attributes are updated
}
void onRoomMemberAttributesUpdated(ZIM * /*zim*/, const std::vector<ZIMRoomMemberAttributesUpdateInfo> & /*infos*/,ZIMRoomOperatedInfo /*operatedInfo*/, const std::string & /*roomID*/) override{
// Write the business logic after the room member attributes are updated
}
When a user in a room calls the setRoomMembersAttributes API:
-
If the number of users in the room is less than or equal to 500, all users in the room will receive the user attribute change notification.
-
If the number of users in the room exceeds 500, only the operator and the user whose attribute is configured or modified will receive the user attribute change notification.
To increase the maximum number of users in the room who can receive the user attribute change notification, developers can contact ZEGOCLOUD technical support.
Batch query room user information
Developers can use the queryRoomMembers interface to query the information of users in a room in bulk by passing the roomID and an array of userIDs. After a successful API call, the callback will return the userList of successfully queried users (which can be used to confirm if the target users are in the room), as well as the errorUserList of failed queries (which can be used to confirm if the target users are not in the room).
The default limit for the number of users that can be queried in bulk is 10.
The sample code is as follows:
String targetUserID = "targetUserIdA";
ArrayList<String> userIDs = new ArrayList<>();
userIDs.add(targetUserID);
// A map that maps userID to ZIMRoomMemberInfo, which can be cached for subsequent UI display. Currently, ZIMRoomMemberInfo exposes userID and userName.
HashMap<String,ZIMRoomMemberInfo> roomMemberMap = new HashMap<>();
ZIM.getInstance().queryRoomMembers(userIDs, "targetRoomID", new ZIMRoomMembersQueriedCallback() {
@Override
public void onRoomMembersQueried(String roomID, ArrayList<ZIMRoomMemberInfo> memberList, ArrayList<ZIMErrorUserInfo> errorUserList, ZIMError errorInfo) {
if(errorInfo.code != ZIMErrorCode.SUCCESS){
Log.d("ZIM CallBack","query room members error! error code:"+errorInfo.code+", error message:"+errorInfo.message);
}
HashMap<String,ZIMErrorUserInfo> targetErrorUserInfoMap = new HashMap<>();
for (ZIMRoomMemberInfo memberInfo:
memberList) {
roomMemberMap.put(memberInfo.userID,memberInfo);
}
// A map that maps failed userID to ZIMErrorUserInfo, if there is a need to pay attention to the failure reason, this data structure can be read
for (ZIMErrorUserInfo errorUserInfo:
errorUserList) {
targetErrorUserInfoMap.put(errorUserInfo.userID,errorUserInfo);
}
// Check if the target member is in the room
boolean isTargetUserIdA = roomMemberMap.containsKey(targetUserID);
}
});
String targetUserID = "targetUserIdA";
ArrayList<String> userIDs = new ArrayList<>();
userIDs.add(targetUserID);
// A map that maps userID to ZIMRoomMemberInfo, which can be cached for subsequent UI display. Currently, ZIMRoomMemberInfo exposes userID and userName.
HashMap<String,ZIMRoomMemberInfo> roomMemberMap = new HashMap<>();
ZIM.getInstance().queryRoomMembers(userIDs, "targetRoomID", new ZIMRoomMembersQueriedCallback() {
@Override
public void onRoomMembersQueried(String roomID, ArrayList<ZIMRoomMemberInfo> memberList, ArrayList<ZIMErrorUserInfo> errorUserList, ZIMError errorInfo) {
if(errorInfo.code != ZIMErrorCode.SUCCESS){
Log.d("ZIM CallBack","query room members error! error code:"+errorInfo.code+", error message:"+errorInfo.message);
}
HashMap<String,ZIMErrorUserInfo> targetErrorUserInfoMap = new HashMap<>();
for (ZIMRoomMemberInfo memberInfo:
memberList) {
roomMemberMap.put(memberInfo.userID,memberInfo);
}
// A map that maps failed userID to ZIMErrorUserInfo, if there is a need to pay attention to the failure reason, this data structure can be read
for (ZIMErrorUserInfo errorUserInfo:
errorUserList) {
targetErrorUserInfoMap.put(errorUserInfo.userID,errorUserInfo);
}
// Check if the target member is in the room
boolean isTargetUserIdA = roomMemberMap.containsKey(targetUserID);
}
});
NSString *userIdA = @"targetUserIdA";
NSString *userIdB = @"targetUserIdB";
NSArray<NSString *> *targetUserIDs = @[userIdA,userIdB];
// A map that maps userID to ZIMRoomMemberInfo, which can be cached for subsequent UI display. Currently, ZIMRoomMemberInfo exposes userID and userName.
NSMutableDictionary *targetRoomMemberMap = [[NSMutableDictionary alloc] init];
[[ZIM getInstance] queryRoomMembersByUserIDs:targetUserIDs roomID:@"targetRoomID" callback:^(NSString * _Nonnull roomID, NSArray<ZIMRoomMemberInfo *> * _Nonnull memberList, NSArray<ZIMErrorUserInfo *> * _Nonnull errorUserList, ZIMError * _Nonnull errorInfo) {
if(errorInfo.code != ZIMErrorCodeSuccess){
NSLog(@"query room members failed! error code:%ld, error message: %@",errorInfo.code, errorInfo.message);
return;
}
// A map that maps userID to ZIMErrorUserInfo, if there is a need to pay attention to the failure reason, you can read this data structure
NSMutableDictionary *targetErrorUserInfoMap = [[NSMutableDictionary alloc] init];
for (ZIMRoomMemberInfo *currentMemberInfo in memberList) {
[targetRoomMemberMap setObject:currentMemberInfo forKey:currentMemberInfo.userID];
}
for (ZIMErrorUserInfo *currentErrorUserInfo in errorUserList){
[targetErrorUserInfoMap setObject:currentErrorUserInfo forKey:currentErrorUserInfo.userID];
}
// Check if the target member is in the room
bool isTargetUserIdAInTheRoom = [[targetRoomMemberMap allKeys] containsObject:userIdA];
}];
NSString *userIdA = @"targetUserIdA";
NSString *userIdB = @"targetUserIdB";
NSArray<NSString *> *targetUserIDs = @[userIdA,userIdB];
// A map that maps userID to ZIMRoomMemberInfo, which can be cached for subsequent UI display. Currently, ZIMRoomMemberInfo exposes userID and userName.
NSMutableDictionary *targetRoomMemberMap = [[NSMutableDictionary alloc] init];
[[ZIM getInstance] queryRoomMembersByUserIDs:targetUserIDs roomID:@"targetRoomID" callback:^(NSString * _Nonnull roomID, NSArray<ZIMRoomMemberInfo *> * _Nonnull memberList, NSArray<ZIMErrorUserInfo *> * _Nonnull errorUserList, ZIMError * _Nonnull errorInfo) {
if(errorInfo.code != ZIMErrorCodeSuccess){
NSLog(@"query room members failed! error code:%ld, error message: %@",errorInfo.code, errorInfo.message);
return;
}
// A map that maps userID to ZIMErrorUserInfo, if there is a need to pay attention to the failure reason, you can read this data structure
NSMutableDictionary *targetErrorUserInfoMap = [[NSMutableDictionary alloc] init];
for (ZIMRoomMemberInfo *currentMemberInfo in memberList) {
[targetRoomMemberMap setObject:currentMemberInfo forKey:currentMemberInfo.userID];
}
for (ZIMErrorUserInfo *currentErrorUserInfo in errorUserList){
[targetErrorUserInfoMap setObject:currentErrorUserInfo forKey:currentErrorUserInfo.userID];
}
// Check if the target member is in the room
bool isTargetUserIdAInTheRoom = [[targetRoomMemberMap allKeys] containsObject:userIdA];
}];
NSString *userIdA = @"targetUserIdA";
NSString *userIdB = @"targetUserIdB";
NSArray<NSString *> *targetUserIDs = @[userIdA,userIdB];
// A map that maps userID to ZIMRoomMemberInfo, which can be cached for subsequent UI display. Currently, ZIMRoomMemberInfo exposes userID and userName.
NSMutableDictionary *targetRoomMemberMap = [[NSMutableDictionary alloc] init];
[[ZIM getInstance] queryRoomMembersByUserIDs:targetUserIDs roomID:@"targetRoomID" callback:^(NSString * _Nonnull roomID, NSArray<ZIMRoomMemberInfo *> * _Nonnull memberList, NSArray<ZIMErrorUserInfo *> * _Nonnull errorUserList, ZIMError * _Nonnull errorInfo) {
if(errorInfo.code != ZIMErrorCodeSuccess){
NSLog(@"query room members failed! error code:%ld, error message: %@",errorInfo.code, errorInfo.message);
return;
}
// A map that maps userID to ZIMErrorUserInfo, if there is a need to pay attention to the failure reason, you can read this data structure
NSMutableDictionary *targetErrorUserInfoMap = [[NSMutableDictionary alloc] init];
for (ZIMRoomMemberInfo *currentMemberInfo in memberList) {
[targetRoomMemberMap setObject:currentMemberInfo forKey:currentMemberInfo.userID];
}
for (ZIMErrorUserInfo *currentErrorUserInfo in errorUserList){
[targetErrorUserInfoMap setObject:currentErrorUserInfo forKey:currentErrorUserInfo.userID];
}
// Check if the target member is in the room
bool isTargetUserIdAInTheRoom = [[targetRoomMemberMap allKeys] containsObject:userIdA];
}];
NSString *userIdA = @"targetUserIdA";
NSString *userIdB = @"targetUserIdB";
NSArray<NSString *> *targetUserIDs = @[userIdA,userIdB];
// A map that maps userID to ZIMRoomMemberInfo, which can be cached for subsequent UI display. Currently, ZIMRoomMemberInfo exposes userID and userName.
NSMutableDictionary *targetRoomMemberMap = [[NSMutableDictionary alloc] init];
[[ZIM getInstance] queryRoomMembersByUserIDs:targetUserIDs roomID:@"targetRoomID" callback:^(NSString * _Nonnull roomID, NSArray<ZIMRoomMemberInfo *> * _Nonnull memberList, NSArray<ZIMErrorUserInfo *> * _Nonnull errorUserList, ZIMError * _Nonnull errorInfo) {
if(errorInfo.code != ZIMErrorCodeSuccess){
NSLog(@"query room members failed! error code:%ld, error message: %@",errorInfo.code, errorInfo.message);
return;
}
// A map that maps userID to ZIMErrorUserInfo, if there is a need to pay attention to the failure reason, you can read this data structure
NSMutableDictionary *targetErrorUserInfoMap = [[NSMutableDictionary alloc] init];
for (ZIMRoomMemberInfo *currentMemberInfo in memberList) {
[targetRoomMemberMap setObject:currentMemberInfo forKey:currentMemberInfo.userID];
}
for (ZIMErrorUserInfo *currentErrorUserInfo in errorUserList){
[targetErrorUserInfoMap setObject:currentErrorUserInfo forKey:currentErrorUserInfo.userID];
}
// Check if the target member is in the room
bool isTargetUserIdAInTheRoom = [[targetRoomMemberMap allKeys] containsObject:userIdA];
}];
string userIdA = "UserIdA";
string userIdB = "UserIdB";
List<string> userIDs = new List<string>();
userIDs.Add(userIdA);
userIDs.Add(userIdB);
ZIM.GetInstance().QueryRoomMembers(userIDs, "roomID", (string roomID, List<ZIMRoomMemberInfo> memberList, List<ZIMErrorUserInfo> errorUserList, ZIMError errorInfo)=>{
if (errorInfo.code == ZIMErrorCode.Success){
// Operation successful.
}
});
string userIdA = "UserIdA";
string userIdB = "UserIdB";
List<string> userIDs = new List<string>();
userIDs.Add(userIdA);
userIDs.Add(userIdB);
ZIM.GetInstance().QueryRoomMembers(userIDs, "roomID", (string roomID, List<ZIMRoomMemberInfo> memberList, List<ZIMErrorUserInfo> errorUserList, ZIMError errorInfo)=>{
if (errorInfo.code == ZIMErrorCode.Success){
// Operation successful.
}
});
ZIM.getInstance().queryRoomMembers(["userA","userB"], "roomID")
.then((ZIMRoomMembersQueriedResult value) {
// Map of userID mapped to ZIMErrorUserInfo, if there is a need to pay attention to the failure reason, you can read this data structure
Map<String, ZIMErrorUserInfo> targetErrorUserInfoMap = {};
Map<String, ZIMRoomMemberInfo> targetRoomMemberMap = {};
for (ZIMRoomMemberInfo currentMemberInfo in value.memberList) {
targetRoomMemberMap[currentMemberInfo.userID] = currentMemberInfo;
}
for (ZIMErrorUserInfo currentErrorUserInfo in value.errorUserList) {
targetErrorUserInfoMap[currentErrorUserInfo.userID] = currentErrorUserInfo;
}
// Check if the target member is in the room
bool isTargetUserIdAInTheRoom = targetRoomMemberMap.containsKey(userIdA);
}).catchError((onError){
// Handle failure
});
ZIM.getInstance().queryRoomMembers(["userA","userB"], "roomID")
.then((ZIMRoomMembersQueriedResult value) {
// Map of userID mapped to ZIMErrorUserInfo, if there is a need to pay attention to the failure reason, you can read this data structure
Map<String, ZIMErrorUserInfo> targetErrorUserInfoMap = {};
Map<String, ZIMRoomMemberInfo> targetRoomMemberMap = {};
for (ZIMRoomMemberInfo currentMemberInfo in value.memberList) {
targetRoomMemberMap[currentMemberInfo.userID] = currentMemberInfo;
}
for (ZIMErrorUserInfo currentErrorUserInfo in value.errorUserList) {
targetErrorUserInfoMap[currentErrorUserInfo.userID] = currentErrorUserInfo;
}
// Check if the target member is in the room
bool isTargetUserIdAInTheRoom = targetRoomMemberMap.containsKey(userIdA);
}).catchError((onError){
// Handle failure
});
const userIDs = ['user1', 'user2'];
zim.queryRoomMembers(userIDs, 'roomID').then(res => {
// Write your business logic here after receiving the query result
});
const userIDs = ['user1', 'user2'];
zim.queryRoomMembers(userIDs, 'roomID').then(res => {
// Write your business logic here after receiving the query result
});
std::vector<std::string> targetUserIDs;
ZIM::getInstance().queryRoomMembers(targetUserIDs, roomID, [targetRoomMemberMap](const std::string &roomID, const std::vector<ZIMRoomMemberInfo> &memberList,const std::vector<ZIMErrorUserInfo> &errorUserList, const ZIMError &errorInfo) {
if (errorInfo.code != ZIMErrorCodeSuccess) {
std::cout << "Query room members failed! error code: " << errorInfo.code << ", error message: " << errorInfo.message << std::endl;
return;
}
// Map of userID to ZIMRoomMemberInfo, can be cached for subsequent UI display. Currently, ZIMRoomMemberInfo exposes userID and userName.
std::map<std::string, ZIMRoomMemberInfo> targetRoomMemberMap;
// Map of userID to ZIMErrorUserInfo, can be used to track failure reasons if needed.
std::map<std::string, ZIMErrorUserInfo> targetErrorUserInfoMap;
for (auto const& currentMemberInfo : memberList) {
targetRoomMemberMap[currentMemberInfo.userID] = currentMemberInfo;
}
for (auto const& currentErrorUserInfo : errorUserList) {
targetErrorUserInfoMap[currentErrorUserInfo.userID] = currentErrorUserInfo;
}
// Check if the target user ID is in the room
bool isTargetUserIdAInTheRoom = std::find(targetRoomMemberMap.begin(), targetRoomMemberMap.end(), userIdA) != targetRoomMemberMap.end();
});
std::vector<std::string> targetUserIDs;
ZIM::getInstance().queryRoomMembers(targetUserIDs, roomID, [targetRoomMemberMap](const std::string &roomID, const std::vector<ZIMRoomMemberInfo> &memberList,const std::vector<ZIMErrorUserInfo> &errorUserList, const ZIMError &errorInfo) {
if (errorInfo.code != ZIMErrorCodeSuccess) {
std::cout << "Query room members failed! error code: " << errorInfo.code << ", error message: " << errorInfo.message << std::endl;
return;
}
// Map of userID to ZIMRoomMemberInfo, can be cached for subsequent UI display. Currently, ZIMRoomMemberInfo exposes userID and userName.
std::map<std::string, ZIMRoomMemberInfo> targetRoomMemberMap;
// Map of userID to ZIMErrorUserInfo, can be used to track failure reasons if needed.
std::map<std::string, ZIMErrorUserInfo> targetErrorUserInfoMap;
for (auto const& currentMemberInfo : memberList) {
targetRoomMemberMap[currentMemberInfo.userID] = currentMemberInfo;
}
for (auto const& currentErrorUserInfo : errorUserList) {
targetErrorUserInfoMap[currentErrorUserInfo.userID] = currentErrorUserInfo;
}
// Check if the target user ID is in the room
bool isTargetUserIdAInTheRoom = std::find(targetRoomMemberMap.begin(), targetRoomMemberMap.end(), userIdA) != targetRoomMemberMap.end();
});