Friend management
Overview
ZIM SDK supports friend management, allowing users to directly add and delete friends, view their friends list, send friend requests to other users, accept or reject friend requests, view friend request lists, check their friend relationship with other users, and query or modify friend information.
Each user can have a maximum of 3000 friends.
Basic functions
By calling the ZIMEventHandler API, you can register callbacks to listen for friend-related events, including: onFriendListChanged, onFriendApplicationListChanged, onFriendApplicationUpdated and onFriendInfoUpdated.
// Friend list change callback
public void onFriendListChanged(ZIM zim, ArrayList<ZIMFriendInfo> friendInfoList,
ZIMFriendListChangeAction action) {}
// Friend information change callback
public void onFriendInfoUpdated(ZIM zim, ArrayList<ZIMFriendInfo> friendInfoList) {}
// Friend application list change callback
public void
onFriendApplicationListChanged(ZIM zim,
ArrayList<ZIMFriendApplicationInfo> friendApplicationInfoList,
ZIMFriendApplicationListChangeAction action) {}
// Friend application information change callback
public void
onFriendApplicationUpdated(ZIM zim,
ArrayList<ZIMFriendApplicationInfo> friendApplicationInfoList) {}
1
// Callback for friend list changes
static void Function(ZIM zim, List<ZIMFriendInfo> friendInfoList ,ZIMFriendListChangeAction action)? onFriendListChanged;
// Callback for friend info updates
static void Function(ZIM zim, List<ZIMFriendInfo> friendInfoList)? onFriendInfoUpdated;
// Callback for friend application list changes
static void Function(ZIM zim,List<ZIMFriendApplicationInfo> friendApplicationInfoList ,ZIMFriendApplicationListChangeAction action)? onFriendApplicationListChanged;
// Callback for friend application updates
static void Function(ZIM zim,List<ZIMFriendApplicationInfo> friendApplicationInfoList)? onFriendApplicationUpdated;
1
// Callback for friend list changes
- (void)zim:(ZIM *)zim
friendListChanged:(NSArray<ZIMFriendInfo *> *)friendInfoList
action:(ZIMFriendListChangeAction)action{
// todo
}
// Callback for friend info updates
- (void)zim:(ZIM *)zim friendInfoUpdated:(NSArray<ZIMFriendInfo *> *)friendInfoList{
// todo
}
// Callback for friend application list changes
- (void)zim:(ZIM *)zim
friendApplicationListChanged:(NSArray<ZIMFriendApplicationInfo *> *)friendApplicationInfoList
action:(ZIMFriendApplicationListChangeAction)action{
// todo
}
// Callback for friend application info updates
- (void)zim:(ZIM *)zim
friendApplicationUpdated:(NSArray<ZIMFriendApplicationInfo *> *)friendApplicationInfoList{
// todo
}
1
// Callback for friend list changes
- (void)zim:(ZIM *)zim
friendListChanged:(NSArray<ZIMFriendInfo *> *)friendInfoList
action:(ZIMFriendListChangeAction)action{
// todo
}
// Callback for friend info updates
- (void)zim:(ZIM *)zim friendInfoUpdated:(NSArray<ZIMFriendInfo *> *)friendInfoList{
// todo
}
// Callback for friend application list changes
- (void)zim:(ZIM *)zim
friendApplicationListChanged:(NSArray<ZIMFriendApplicationInfo *> *)friendApplicationInfoList
action:(ZIMFriendApplicationListChangeAction)action{
// todo
}
// Callback for friend application info updates
- (void)zim:(ZIM *)zim
friendApplicationUpdated:(NSArray<ZIMFriendApplicationInfo *> *)friendApplicationInfoList{
// todo
}
1
// Friend list changed callback
zim.on('friendListChanged', (zim, data) => {
// todo
});
// Friend info updated callback
zim.on('friendInfoUpdated', (zim, data) => {
// todo
});
// Friend application list changed callback
zim.on('friendApplicationListChanged', (zim, data) => {
// todo
});
// Friend application updated callback
zim.on('friendApplicationUpdated', (zim, data) => {
// todo
});
1
// Register SDK event notification callback
zim->setEventHandler(shared_from_this());
...
// Callback for friend list changes
void onFriendListChanged(ZIM * /*zim*/,
const std::vector<ZIMFriendInfo> & /*friendInfoList*/,
ZIMFriendListChangeAction & /*action*/) {
//todo
}
// Callback for friend information updates
void onFriendInfoUpdated(ZIM * /*zim*/,
const std::vector<ZIMFriendInfo> & /*friendInfoList*/) {
//todo
}
// Callback for friend application list changes
void onFriendApplicationListChanged(
ZIM * /*zim*/, const std::vector<ZIMFriendApplicationInfo> & /*friendApplicationInfoList*/,
ZIMFriendApplicationListChangeAction & /*action*/) {
//todo
}
// Callback for friend application information updates
void onFriendApplicationUpdated(
ZIM * /*zim*/,
const std::vector<ZIMFriendApplicationInfo> & /*friendApplicationInfoList*/) {
//todo
}
1
Add friends directly
After logging in to the ZIM SDK, users can use the addFriend API to directly add other users as friends without requiring their consent. This allows users to set friend remarks and attributes for the added user.
You can set up to 5 friend attributes, and the corresponding key
values must be k0, k1, k2, k3, and k4. It is recommended that you agree in advance on the actual meanings of each attribute and maintain consistency.
The result of adding a friend is returned through the ZIMFriendAddedResult .
// Add friends directly
ZIMFriendAddConfig config = new ZIMFriendAddConfig();
config.friendAlias = "zego"
config.friendAttributes.put("k0", "v0");
config.wording = "How are you";
ZIM.getInstance().addFriend("zego", config, new ZIMFriendAddedCallback() {
@Override
public void onFriendAddedCallback(ZIMFriendInfo friendInfo, ZIMError zimError) {
}
);
1
// Add friend directly
try{
ZIMFriendAddConfig config = ZIMFriendAddConfig();
config.friendAlias = 'zego';
config.friendAttributes['k0'] = 'v0';
config.wording = 'Long time no see, old classmate';
ZIMFriendAddedResult result = await ZIM.getInstance()!.addFriend("zego", config);
// Handle success logic
} on PlatformException catch (onError){
// Handle failure logic
onError.code; // Handle according to the official error code table
onError.message; // Error message
}
1
// Add friend directly
ZIMFriendAddConfig *addConfig = [[ZIMFriendAddConfig alloc] init];
addConfig.wording = @"hello";
addConfig.friendAlias = @"Mark";
addConfig.friendAttributes = @{@"k0":@"SZ"};
[[ZIM getInstance] addFriendByUserID:@"userID" config:addConfig callback:^(ZIMFriendInfo * _Nonnull friendInfo, ZIMError * _Nonnull errorInfo) {
}];
1
// Add friend directly
ZIMFriendAddConfig *addConfig = [[ZIMFriendAddConfig alloc] init];
addConfig.wording = @"hello";
addConfig.friendAlias = @"Mark";
addConfig.friendAttributes = @{@"k0":@"SZ"};
[[ZIM getInstance] addFriendByUserID:@"userID" config:addConfig callback:^(ZIMFriendInfo * _Nonnull friendInfo, ZIMError * _Nonnull errorInfo) {
}];
1
// Add friends directly
zim.addFriend('userID', { wording: 'Hello!', friendAlias: 'Mark', friendAttributes: { k0: 'SZ' } }).then(res => {
const friendInfo = res.friendInfo;
});
1
// Add friend directly
ZIMFriendAddConfig config;
config.wording = "Hello!";
config.friendAlias = "Mark";
config.friendAttributes["k0"] = "SZ";
zim::ZIM::getInstance()->addFriend("userID", config, (const zim::ZIMFriendInfo &friendInfo, const zim::ZIMError &errorInfo){
if(errorInfo.code == ZIMErrorCodeSuccess) {
// ......
} else {
// ......
}
}
1
After successfully adding a friend, the related users will receive the callback onFriendListChanged to notify them that the user has become a friend.
Batch deleting friends
After logging in to the ZIM SDK, users can use the deleteFriends API to batch delete up to 20 friends in a one-way or two-way deletion manner.
In this example, one-way deletion and two-way deletion are explained.
- One-way deletion: If user A deletes user B in a one-way manner, user B is no longer a friend of user A, but not vice versa.
- Two-way deletion: If user A deletes user B in a two-way manner, they are no longer friends with each other.
The result of deleting friends is returned through ZIMFriendsDeletedCallback.
// Batch deleting friends
// When the type is set to BOTH: Perform a two-way deletion
// When the type is set to SINGLE: Perform a one-way deletion
ZIMFriendDeleteConfig zimFriendDeleteConfig = new ZIMFriendDeleteConfig();
zimFriendDeleteConfig.type = ZIMFriendDeleteType.BOTH;
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add("zego");
ZIM.getInstance().deleteFriends(arrayList, zimFriendDeleteConfig, new ZIMFriendsDeletedCallback() {
@Override
public void onFriendsDeletedCallback(ArrayList<ZIMErrorUserInfo> errorUserList, ZIMError zimError) {
// Delete result callback.
}
});
1
// Batch delete friends
// type is both: bilateral deletion
// type is single: unilateral deletion
try{
ZIMFriendDeleteConfig friendDeleteConfig = ZIMFriendDeleteConfig();
friendDeleteConfig.type = ZIMFriendDeleteType.single;
List<String> list = [];
list.add('zego');
ZIMFriendsDeletedResult result = await ZIM.getInstance()!.deleteFriends(list, friendDeleteConfig);
// Handle success logic
} on PlatformException catch (onError){
// Handle failure logic
onError.code; // Handle according to the official error code table
onError.message; // Error message
}
1
// Batch delete friends
// type is ZIMFriendDeleteTypeBoth: bilateral deletion
// type is ZIMFriendDeleteTypeSingle: unilateral deletion
ZIMFriendDeleteConfig *friendDeleteConfig = [[ZIMFriendDeleteConfig alloc] init];
friendDeleteConfig.type = ZIMFriendDeleteTypeBoth;
[[ZIM getInstance] deleteFriendsByUserIDs:@[@"userID1",@"userID2"] config:friendDeleteConfig callback:^(NSArray<ZIMErrorUserInfo *> * _Nonnull errorUserList, ZIMError * _Nonnull errorInfo) {
}];
1
// Batch delete friends
// type is ZIMFriendDeleteTypeBoth: bilateral deletion
// type is ZIMFriendDeleteTypeSingle: unilateral deletion
ZIMFriendDeleteConfig *friendDeleteConfig = [[ZIMFriendDeleteConfig alloc] init];
friendDeleteConfig.type = ZIMFriendDeleteTypeBoth;
[[ZIM getInstance] deleteFriendsByUserIDs:@[@"userID1",@"userID2"] config:friendDeleteConfig callback:^(NSArray<ZIMErrorUserInfo *> * _Nonnull errorUserList, ZIMError * _Nonnull errorInfo) {
}];
1
// Batch delete friends
// type 0: bilateral deletion
// type 1: unilateral deletion
zim.deleteFriends(['userID1', 'userID2'], { type: 0 }).then(res => {
const errorUserList = res.errorUserList;
})
1
// Batch delete friends
// type is ZIM_FRIEND_DELETE_TYPE_BOTH: delete in both directions
// type is ZIM_FRIEND_DELETE_TYPE_SINGLE: delete in one direction
zim::ZIMFriendDeleteConfig config;
config.type = ZIM_FRIEND_DELETE_TYPE_BOTH;
std::vector<std::string> userIDs;
userIDs.emplace_back("userID1");
zim::ZIM::getInstance()->deleteFriends(userIDs, config, [=](
const std::vector<zim::ZIMErrorUserInfo>& errorUserList, const zim::ZIMError& errorInfo) {
if(errorInfo.code == ZIMErrorCodeSuccess) {
// ......
} else {
// ......
}
});
1
After successfully deleting a friend, depending on the deletion type, the related users will receive the callback onFriendListChanged to notify them that the user is no longer a friend.
Send friend requests
After logging in to the ZIM SDK, users can use the sendFriendApplication API to send friend requests to other users and set friend remarks and attributes.
You can set up to 5 friend attributes, and the corresponding key
values must be k0, k1, k2, k3, and k4. It is recommended that you agree in advance on the actual meanings of each attribute and maintain consistency.
The result of sending a friend request is returned through ZIMFriendApplicationSentResult.
// Send friend requests
ZIMFriendApplicationSendConfig config = new ZIMFriendApplicationSendConfig();
config.friendAlias = "zego"
config.wording = "How are you";
ZIM.getInstance().sendFriendApplication("zego", config, new ZIMFriendApplicationSentCallback() {
@Override
public void onFriendApplicationSentCallback( ZIMFriendApplicationInfo applicationInfoList, ZIMError errorInfo) {
// Handling friend request results
}
});
1
// Send friend application
try{
ZIMFriendApplicationSendConfig config = ZIMFriendApplicationSendConfig();
config.friendAlias = 'zego';
config.wording = 'Hello old friend';
ZIMFriendApplicationSentResult result = await ZIM.getInstance()!.sendFriendApplication('zego', config);
// Handle success logic
} on PlatformException catch (onError){
// Handle failure logic
onError.code; // Handle according to the official error code table
onError.message; // Error message
}
1
// Send friend application
ZIMFriendApplicationSendConfig *sendConfig = [[ZIMFriendApplicationSendConfig alloc] init];
sendConfig.wording = @"Hello!";
sendConfig.friendAlias = @"Mark";
sendConfig.friendAttributes = @{@"k0":@"SZ"};
[[ZIM getInstance] sendFriendApplicationToUserID:@"userID" config:sendConfig callback:^(ZIMFriendApplicationInfo * _Nonnull applicationInfo, ZIMError * _Nonnull errorInfo) {
}];
1
// Send friend application
ZIMFriendApplicationSendConfig *sendConfig = [[ZIMFriendApplicationSendConfig alloc] init];
sendConfig.wording = @"Hello!";
sendConfig.friendAlias = @"Mark";
sendConfig.friendAttributes = @{@"k0":@"SZ"};
[[ZIM getInstance] sendFriendApplicationToUserID:@"userID" config:sendConfig callback:^(ZIMFriendApplicationInfo * _Nonnull applicationInfo, ZIMError * _Nonnull errorInfo) {
}];
1
// Receive friend application list callback
zim.on('friendApplicationListChanged', (zim, data) => {
// action is 0: new
const { action, applicationList } = data;
});
1
// Send friend application
zim::ZIMFriendApplicationSendConfig config;
config.friendAlias = "Mark";
config.friendAttributes["k0"] = "SZ";
zim::ZIM::getInstance()->sendFriendApplication("userID", config, [=](const zim::ZIMFriendApplicationInfo& applicationInfo, const zim::ZIMError& errorInfo) {
if(errorInfo.code == ZIMErrorCodeSuccess) {
// ......
} else {
// ......
}
});
1
The target user will receive the onFriendApplicationListChanged callback, indicating that a user has requested to become friends. The user can choose to accept or reject the request within 7 days.
If you need to adjust the friend application validity period, please contact the ZEGOCLOUD technical support team.
// Received friend request list callback
public void onFriendApplicationListChanged(ZIM zim,
ArrayList<ZIMFriendApplicationInfo> friendApplicationInfoList, ZIMFriendApplicationListChangeAction action) {
}
1
Accept friend requests
After logging in to ZIM SDK, users can call the acceptFriendApplication API, passing the ID of the user who initiated the request, to accept a friend request.
The result of accepting a friend request is returned through ZIMFriendApplicationAcceptedResult.
// Accept friend requests
ZIMFriendApplicationAcceptConfig config = new ZIMFriendApplicationAcceptConfig();
config.friendAlias = "zego";
config.friendAttributes = new
ZIM.getInstance().acceptFriendApplication("zego", config, new ZIMFriendApplicationAcceptedCallback() {
@Override
public void onFriendApplicationAccepted(ZIMFriendInfo friendInfo, ZIMError zimError) {
}
});
1
// Accept friend application
try{
ZIMFriendApplicationAcceptConfig acceptConfig = ZIMFriendApplicationAcceptConfig();
acceptConfig.friendAlias = 'Mark';
acceptConfig.friendAttributes = {'k0':'SZ'};
ZIMFriendApplicationAcceptedResult result = await ZIM.getInstance()!.acceptFriendApplication('zego', config);
// Handle success logic
} on PlatformException catch (onError){
// Handle failure logic
onError.code; // Handle according to the official error code document
onError.message; // Error message
}
1
// Accept friend application
ZIMFriendApplicationAcceptConfig *acceptConfig = [[ ZIMFriendApplicationAcceptConfig alloc] init];
acceptConfig.friendAlias = @"Mark";
acceptConfig.friendAttributes = @{@"k0":@"SZ"};
[[ZIM getInstance] acceptFriendApplicationFromUserID:@"userID" config:acceptConfig callback:^(ZIMFriendInfo * _Nonnull friendInfo, ZIMError * _Nonnull errorInfo) {
}];
1
// Accept friend application
ZIMFriendApplicationAcceptConfig *acceptConfig = [[ ZIMFriendApplicationAcceptConfig alloc] init];
acceptConfig.friendAlias = @"Mark";
acceptConfig.friendAttributes = @{@"k0":@"SZ"};
[[ZIM getInstance] acceptFriendApplicationFromUserID:@"userID" config:acceptConfig callback:^(ZIMFriendInfo * _Nonnull friendInfo, ZIMError * _Nonnull errorInfo) {
}];
1
// Accept friend application
zim.acceptFriendApplication('userID', { friendAlias: 'Mark', friendAttributes: { k0: 'SZ' } }).then(res => {
const friendInfo = res.friendInfo;
})
1
// Accept friend request
zim::ZIMFriendApplicationAcceptConfig config;
config.friendAlias = "Mark";
config.friendAttributes["k0"] = "SZ";
zim::ZIM::getInstance()->acceptFriendApplication("userID", config, [=](const zim::ZIMFriendInfo& friendInfo, const zim::ZIMError& errorInfo) {
if(errorInfo.code == ZIMErrorCodeSuccess) {
// ......
} else {
// ......
}
1
Both the requesting user and the requested user will not only receive the onFriendApplicationUpdated to know that the other user has become their friend.
Reject friend requests
After logging in to ZIM SDK, users can reject friend requests by using the rejectFriendApplication API.
The result of rejecting a friend request is returned through ZIMFriendApplicationRejectedResult.
// Reject friend requests
ZIMFriendApplicationRejectConfig config = new ZIMFriendApplicationRejectConfig();
ZIM.getInstance().rejectFriendApplication("zego", config, new ZIMFriendApplicationRejectedCallback() {
@Override
public void onFriendApplicationRejected(ZIMUserInfo zimUserInfo, ZIMError zimError) {
// Rejecting friend request result
}
});
1
// Reject friend application
try{
ZIMFriendApplicationRejectConfig config = ZIMFriendApplicationRejectConfig();
ZIMFriendApplicationRejectedResult result = await ZIM.getInstance()!.rejectFriendApplication('zego', config);
// Handle success logic
} on PlatformException catch (onError){
// Handle failure logic
onError.code; // Handle according to the official error code table
onError.message; // Error message
}
1
// Reject friend application
ZIMFriendApplicationRejectConfig *rejectConfig = [[ZIMFriendApplicationRejectConfig alloc] init];
[[ZIM getInstance] rejectFriendApplicationFromUserID:@"userID" config:rejectConfig callback:^(ZIMUserInfo * _Nonnull userInfo, ZIMError * _Nonnull errorInfo) {
}];
1
// Reject friend application
ZIMFriendApplicationRejectConfig *rejectConfig = [[ZIMFriendApplicationRejectConfig alloc] init];
[[ZIM getInstance] rejectFriendApplicationFromUserID:@"userID" config:rejectConfig callback:^(ZIMUserInfo * _Nonnull userInfo, ZIMError * _Nonnull errorInfo) {
}];
1
// Reject friend application
zim.rejectFriendApplication('userID', {} }).then(res => {
const userInfo = res.userInfo;
})
1
// Reject friend request
zim::ZIMFriendApplicationRejectConfig config;
zim::ZIM::getInstance()->rejectFriendApplication("userID", config, [=](const zim::ZIMUserInfo& userInfo, const zim::ZIMError& errorInfo) {
if(errorInfo.code == ZIMErrorCodeSuccess) {
// ......
} else {
// ......
}
});
1
Both the requesting user and the requested user will receive the onFriendApplicationUpdated callback to know that the application has been rejected.
Query friend list
After logging in to the ZIM SDK, users can use the queryFriendList API to retrieve the paginated complete friends list.
The query results are returned through ZIMFriendListQueriedResult, and the returned friends list is sorted in descending order based on the time of friend relationship creation.
// Query Friends List
ZIMFriendListQueryConfig config = new ZIMFriendListQueryConfig();
config.count = 3000;
config.nextFlag = 0;
ZIM.getInstance().queryFriendList(config, new ZIMFriendListQueriedCallback() {
@Override
public void onFriendListQueried(ArrayList<ZIMFriendInfo> friendList, int nextFlag, ZIMError errorInfo) {
}
});
1
// Query friend information list
try{
ZIMFriendListQueryConfig config = ZIMFriendListQueryConfig();
config.count = 3000;
config.nextFlag = 0;
ZIMFriendListQueriedResult result = await ZIM.getInstance()!.queryFriendList(config);
// Handle success logic
} on PlatformException catch (onError){
// Handle failure logic
onError.code; // Handle according to the official error code table
onError.message; // Error message
}
1
// Query the list of friend information
ZIMFriendListQueryConfig *queryConfig = [[ ZIMFriendListQueryConfig alloc] init];
queryConfig.count = 100;
queryConfig.nextFlag = 0;
[[ZIM getInstance] queryFriendListWithConfig:queryConfig callback:^(NSArray<ZIMFriendInfo *> * _Nonnull friendList, unsigned int nextFlag, ZIMError * _Nonnull errorInfo) {
}];
1
// Query the list of friend information
ZIMFriendListQueryConfig *queryConfig = [[ ZIMFriendListQueryConfig alloc] init];
queryConfig.count = 100;
queryConfig.nextFlag = 0;
[[ZIM getInstance] queryFriendListWithConfig:queryConfig callback:^(NSArray<ZIMFriendInfo *> * _Nonnull friendList, unsigned int nextFlag, ZIMError * _Nonnull errorInfo) {
}];
1
// Query friend information list
zim.queryFriendList({ count: 100, nextFlag: 0 }).then(res => {
const { friendList, nextFlag } = res;
});
1
// Query friend information list
zim::ZIMFriendListQueryConfig config;
config.count = 100;
config.nextFlag = 0;
zim::ZIM::getInstance()->queryFriendList(config, [=](const std::vector<zim::ZIMFriendInfo>& friendList, unsigned int nextFlag,
const zim::ZIMError& errorInfo) {
if(errorInfo.code == ZIMErrorCodeSuccess) {
// ......
} else {
// ......
}
});
1
Query friend request list
After logging in to the ZIM SDK, users can use the queryFriendApplicationList API to retrieve the friend request list and understand the status of each request. The friend request list includes both the requests initiated by the user to other users and the requests initiated by other users to the user.
The query results are returned through ZIMFriendApplicationListQueriedResult.
// Query friend application information list
ZIMFriendApplicationListQueryConfig config = new ZIMFriendApplicationListQueryConfig();
config.count = 3000;
config.nextFlag = 0;
ZIM.getInstance().queryFriendApplicationList(config, new ZIMFriendApplicationListQueriedCallback() {
@Override
public void onFriendApplicationListQueried(ArrayList<ZIMFriendApplicationInfo> applicationList, int nextFlag, ZIMError errorInfo) {
}
});
1
// Query friend application information list
try {
ZIMFriendApplicationListQueryConfig config = ZIMFriendApplicationListQueryConfig();
config.count = 3000;
config.nextFlag = 0;
ZIMFriendApplicationListQueriedResult result = await ZIM.getInstance()!.queryFriendApplicationList(config);
// Handle success logic
} on PlatformException catch (onError) {
// Handle failure logic
onError.code; // Handle according to the official error code table
onError.message; // Error message
}
1
// Query friend application information list
ZIMFriendApplicationListQueryConfig *queryConfig = [[ZIMFriendApplicationListQueryConfig alloc] init];
queryConfig.count = 100;
queryConfig.nextFlag = 0;
[[ZIM getInstance] queryFriendApplicationListWithConfig:queryConfig callback:^(NSArray<ZIMFriendApplicationInfo *> * _Nonnull applicationList, unsigned int nextFlag, ZIMError * _Nonnull errorInfo) {
}];
1
// Query friend application information list
ZIMFriendApplicationListQueryConfig *queryConfig = [[ZIMFriendApplicationListQueryConfig alloc] init];
queryConfig.count = 100;
queryConfig.nextFlag = 0;
[[ZIM getInstance] queryFriendApplicationListWithConfig:queryConfig callback:^(NSArray<ZIMFriendApplicationInfo *> * _Nonnull applicationList, unsigned int nextFlag, ZIMError * _Nonnull errorInfo) {
}];
1
// Query friend application information list
zim.queryFriendApplicationList({ count: 100, nextFlag: 0 }).then(res => {
const { applicationList, nextFlag } = res;
});
1
// Query friend application information list
zim::ZIMFriendApplicationListQueryConfig config;
config.count = 100;
config.nextFlag = 0;
zim::ZIM::getInstance()->queryFriendApplicationList(config, [=](const std::vector<zim::ZIMFriendApplicationInfo>& applicationList,
unsigned int nextFlag, const zim::ZIMError& errorInfo) {
if(errorInfo.code == ZIMErrorCodeSuccess) {
// ......
} else {
// ......
}
});
1
More functions
Update friend alias
After logging in to the ZIM SDK, users can update the alias they have for a friend using the updateFriendAlias API.
The result of the update is returned through ZIMFriendAliasUpdatedResult.
// Update friend alias
ZIM.getInstance().updateFriendAlias("Classmate A", "zego", new ZIMFriendAliasUpdatedCallback() {
@Override
public void onFriendAliasUpdated(ZIMFriendInfo friendInfo, ZIMError zimError) {
}
});
1
// Update friend alias
try {
ZIMFriendAliasUpdatedResult result = await ZIM.getInstance()!.updateFriendAlias('A同学', 'zego');
// Handle success logic
} on PlatformException catch (onError) {
// Handle failure logic
onError.code; // Handle according to the official error code table
onError.message; // Error message
}
1
// Update friend alias
[[ZIM getInstance] updateFriendAlias:@"New Alias" userID:@"userID" callback:^(ZIMFriendInfo * _Nonnull friendInfo, ZIMError * _Nonnull errorInfo) {
}];
1
// Update friend alias
[[ZIM getInstance] updateFriendAlias:@"New Alias" userID:@"userID" callback:^(ZIMFriendInfo * _Nonnull friendInfo, ZIMError * _Nonnull errorInfo) {
}];
1
// Update friend remark
zim.updateFriendAlias('New remark', 'userID' }).then(res => {
const friendInfo = res.friendInfo;
});
1
// Update friend alias
zim::ZIM::getInstance()->updateFriendAlias("New Alias", "userID", [=](const zim::ZIMFriendInfo& friendInfo, const zim::ZIMError& errorInfo) {
if(errorInfo.code == ZIMErrorCodeSuccess) {
// ......
} else {
// ......
}
});
1
After a successful update, the user can receive the onFriendInfoUpdated callback to know that the friend's information has been updated.
Update friend attributes
After logging in to the ZIM SDK, users can update friend attributes using the updateFriendAttributes API.
You can set up to 5 friend attributes, and the corresponding key
values must be k0, k1, k2, k3, and k4. It is recommended that you agree in advance on the actual meanings of each attribute and maintain consistency.
The result of updating friend attributes is returned through ZIMFriendAttributesUpdatedResult.
HashMap<String, String> friendAttributes = new HashMap<String, String>();
friendAttributes.put("k0","v0");
// Update friend attributes
zim.updateFriendAttributes(friendAttributes, "zego", new ZIMFriendAttributesUpdatedCallback(){
public void onFriendAttributesUpdated(ZIMFriendInfo friendInfo, ZIMError errorInfo) {
}
});
1
// Update friend attributes
zim.updateFriendAttributes({ k1: 'v1', k2: 'v2' } , 'userID' }).then(res => {
const friendInfo = res.friendInfo;
});
1
// Update friend attributes
[[ZIM getInstance] updateFriendAttributes:@{@"k1":@"v1",@"k2":@"v2"} userID:@"userID" callback:^(ZIMFriendInfo * _Nonnull friendInfo, ZIMError * _Nonnull errorInfo) {
}];
1
// Update friend attributes
[[ZIM getInstance] updateFriendAttributes:@{@"k1":@"v1",@"k2":@"v2"} userID:@"userID" callback:^(ZIMFriendInfo * _Nonnull friendInfo, ZIMError * _Nonnull errorInfo) {
}];
1
// Update friend attributes
zim.updateFriendAttributes({ k1: 'v1', k2: 'v2' } , 'userID' }).then(res => {
const friendInfo = res.friendInfo;
});
1
// Update friend attributes
std::unordered_map<std::string, std::string> friendAttributes;
friendAttributes["k1"] = "v1";
friendAttributes["k2"] = "v2";
zim::ZIM::getInstance()->updateFriendAttributes(friendAttributes, "userID", [=](const zim::ZIMFriendInfo& friendInfo, const zim::ZIMError& errorInfo) {
if(errorInfo.code == ZIMErrorCodeSuccess) {
// ......
} else {
// ......
}
});
1
After logging in to the ZIM SDK, users can update friend attributes using the onFriendInfoUpdated API.
Check friend relationships
After logging in to the ZIM SDK, users can use the checkFriendsRelation API to batch check their friend relationships with up to 20 other users.
ZEGOCLOUD allows one-way or two-way check of friendships. In this example, the friendship between users A and B is checked.
- One-way check: Only checks whether user B is in the friend list of user A.
- Two-way check: Checks whether users A and B are in the friend list of the other.
The result of checking friend relationships is returned through ZIMFriendsRelationCheckedResult.
// Check friend relationships with other users
// When the type is set to BOTH: Perform a two-way check
// When the type is set to SINGLE: Perform a one-way check
ArrayList<String> userIDs = new ArrayList<>();
userIDs.add("zego");
ZIMFriendRelationCheckConfig config = new ZIMFriendRelationCheckConfig();
config.type = ZIMFriendRelationCheckType.BOTH;
ZIM.getInstance().checkFriendsRelation(userIDs, config, new ZIMFriendsRelationCheckedCallback() {
@Override
public void onFriendsChecked(ArrayList<ZIMFriendRelationInfo> relationInfos, ArrayList<ZIMErrorUserInfo> errorUserList, ZIMError errorInfo) {
}
});
1
// Check friend relationship with other users
// type is both: bidirectional
// type is single: unidirectional
try {
ZIMFriendAttributesUpdatedResult result = await ZIM.getInstance()!.updateFriendAttributes(
{'k1':'v1','k2':'v2'}, 'zego');
// Handle success logic
} on PlatformException catch (onError) {
// Handle failure logic
onError.code; // Handle according to the official error code table
onError.message; // Error message
}
1
// Check friend relationship with other users
// type is ZIMFriendRelationCheckTypeBoth: bidirectional
// type is ZIMFriendRelationCheckTypeSingle: unidirectional
ZIMFriendRelationCheckConfig *checkConfig = [[ZIMFriendRelationCheckConfig alloc] init];
checkConfig.type = ZIMFriendRelationCheckTypeSingle;
[[ZIM getInstance] checkFriendsRelationByUserIDs:@[@"userID1",@"userID2"] config:checkConfig callback:^(NSArray<ZIMFriendRelationInfo *> * _Nonnull relationInfos, NSArray<ZIMErrorUserInfo *> * _Nonnull errorUserList, ZIMError * _Nonnull errorInfo) {
}];
1
// Check friend relationship with other users
// type is ZIMFriendRelationCheckTypeBoth: bidirectional
// type is ZIMFriendRelationCheckTypeSingle: unidirectional
ZIMFriendRelationCheckConfig *checkConfig = [[ZIMFriendRelationCheckConfig alloc] init];
checkConfig.type = ZIMFriendRelationCheckTypeSingle;
[[ZIM getInstance] checkFriendsRelationByUserIDs:@[@"userID1",@"userID2"] config:checkConfig callback:^(NSArray<ZIMFriendRelationInfo *> * _Nonnull relationInfos, NSArray<ZIMErrorUserInfo *> * _Nonnull errorUserList, ZIMError * _Nonnull errorInfo) {
}];
1
// Check friend relationship with other users
// type is 0: bidirectional
// type is 1: unidirectional
zim.checkFriendsRelation(['userID1', 'userID2'], { type: 0 } }).then(res => {
const { relationInfos, errorUserList } = res;
})
1
// Check the friend relationship with other users
// type is ZIM_FRIEND_RELATION_CHECK_TYPE_BOTH: bidirectional
// type is ZIM_FRIEND_RELATION_CHECK_TYPE_SINGLE: unidirectional
std::vector<std::string> userIDs;
userIDs.emplace_back("userID1");
zim::ZIMFriendRelationCheckConfig config;
config.type = ZIM_FRIEND_RELATION_CHECK_TYPE_BOTH;
zim::ZIM::getInstance()->checkFriendsRelation(userIDs, config, [=](
const std::vector<zim::ZIMFriendRelationInfo>& relationInfos,
const std::vector<zim::ZIMErrorUserInfo>& errorUserList, const zim::ZIMError& errorInfo) {
if(errorInfo.code == ZIMErrorCodeSuccess) {
// ......
} else {
// ......
}
});
1
After logging in to the ZIM SDK, users can use the queryFriendsInfo API to batch query information for up to 20 friends.
The result of batch querying friend information is returned through ZIMFriendsInfoQueriedResult.
// Batch query friend information
ArrayList<String> userIDs = new ArrayList<>();
userIDs.add("zego");
ZIM.getInstance().queryFriendsInfo(userIDs, new ZIMFriendsInfoQueriedCallback() {
@Override
public void onFriendsInfoQueried(ArrayList<ZIMFriendInfo> friendInfos, ArrayList<ZIMErrorUserInfo> errorUserList, ZIMError errorInfo) {
}
});
1
// Batch query friends info
try {
List<String> userIDs = ['zego'];
userIDs.add('zego');
ZIMFriendsInfoQueriedResult result = await ZIM.getInstance()!.queryFriendsInfo(userIDs);
// Handle success logic
} on PlatformException catch (onError) {
// Handle failure logic
onError.code; // Handle according to the official error code table
onError.message; // Error message
}
1
// Query friend information in batch
[[ZIM getInstance] queryFriendsInfoByUserIDs:@[@"userID1",@"userID2"] callback:^(NSArray<ZIMFriendInfo *> * _Nonnull friendInfos, NSArray<ZIMErrorUserInfo *> * _Nonnull errorUserList, ZIMError * _Nonnull errorInfo) {
}];
1
// Query friend information in batch
[[ZIM getInstance] queryFriendsInfoByUserIDs:@[@"userID1",@"userID2"] callback:^(NSArray<ZIMFriendInfo *> * _Nonnull friendInfos, NSArray<ZIMErrorUserInfo *> * _Nonnull errorUserList, ZIMError * _Nonnull errorInfo) {
}];
1
// Batch query friend information
zim.queryFriendsInfo(['userID1', 'userID2']).then(res => {
const { friendInfos, errorUserList } = res;
});
1
// Batch query friend information
std::vector<std::string> userIDs;
userIDs.emplace_back("userID1");
zim::ZIM::getInstance()->queryFriendsInfo(userIDs, [=](
const std::vector<zim::ZIMFriendInfo>& friendInfos,
const std::vector<zim::ZIMErrorUserInfo>& errorUserList, const zim::ZIMError& errorInfo) {
if(errorInfo.code == ZIMErrorCodeSuccess) {
// ......
} else {
// ......
}
});
1
Search for friends
After logging in to the ZIM SDK, users can use the searchLocalFriends API to search for friends based on their usernames and aliases. Users can provide up to 5 keywords to search for friends who match all the provided keywords.
The search results are returned through ZIMFriendsSearchedResult.
ZIMFriendSearchConfig config = new ZIMFriendSearchConfig();
config.count = 100;
config.nextFlag = 0;
config.isAlsoMatchFriendAlias = true;
config.keywords.add("zego");
ZIM.getInstance().searchLocalFriends(config, new ZIMFriendsSearchedCallback() {
@Override
public void onFriendsSearched(ArrayList<ZIMFriendInfo> friendInfos, int nextFlag, ZIMError errorInfo)
{
}
});
1
try {
ZIMFriendSearchConfig config = ZIMFriendSearchConfig();
config.count = 100;
config.nextFlag = 0;
config.isAlsoMatchFriendAlias = true;
config.keywords.add('zego');
ZIMFriendsSearchedResult result = await ZIM.getInstance()!.searchLocalFriends(config);
// Handle success logic
} on PlatformException catch (onError) {
// Handle failure logic
onError.code; // Handle according to the official error code table
onError.message; // Error message
}
1
ZIMFriendSearchConfig *searchConfig = [[ZIMFriendSearchConfig alloc] init];
searchConfig.count = 100;
searchConfig.keywords = @[@"a",@"b"];
searchConfig.isAlsoMatchFriendAlias = YES;
searchConfig.nextFlag = 0;
[[ZIM getInstance] searchLocalFriendsWithConfig:searchConfig callback:^(NSArray<ZIMFriendInfo *> * _Nonnull friendInfos, unsigned int nextFlag, ZIMError * _Nonnull errorInfo) {
}];
1
ZIMFriendSearchConfig *searchConfig = [[ZIMFriendSearchConfig alloc] init];
searchConfig.count = 100;
searchConfig.keywords = @[@"a",@"b"];
searchConfig.isAlsoMatchFriendAlias = YES;
searchConfig.nextFlag = 0;
[[ZIM getInstance] searchLocalFriendsWithConfig:searchConfig callback:^(NSArray<ZIMFriendInfo *> * _Nonnull friendInfos, unsigned int nextFlag, ZIMError * _Nonnull errorInfo) {
}];
1
zim.searchLocalFriends({ keywords: ['a', 'b'], isAlsoMatchFriendAlias: true, count: 100, nextFlag: 0 }).then(res => {
// todo
});
1
ZIMFriendSearchConfig config;
config.count = 100;
config.isAlsoMatchFriendAlias = true;
config.nextFlag = 0;
config.keywords.emplace_back("a");
config.keywords.emplace_back("b");
zim::ZIM::getInstance()->searchLocalFriends(config, [=](const std::vector<zim::ZIMFriendInfo>& friendInfos, unsigned int nextFlag,
const zim::ZIMError& errorInfo) {
if(errorInfo.code == ZIMErrorCodeSuccess) {
// ......
} else {
// ......
}
});
1