Blacklist management
Blacklisting and friend operations do not affect each other. Taking user A and B as friends as an example:
- User A can blacklist user B, but they will still be friends.
- If at this point, user A and user B end their friendship, user B will still be on user A's blacklist.
- Afterwards, if user A removes user B from the blacklist, user B will still not be user A's friend.
Function Introduction
You can check your blacklist, blacklist a specified user (no longer receiving messages from that user), move out of the blacklist, and check if a specified user is in the blacklist.
Implementation Process
Query Blacklist
After logging in to the ZIM SDK, users can query the blacklist by using the queryBlacklistWithConfig interface.
The query result is returned through the ZIMBlacklistQueriedCallback.
// Query blacklist
ZIMBlacklistQueryConfig config = new ZIMBlacklistQueryConfig();
// Fill in the number of user information to be obtained at one time
config.count = 100;
// Fill in the pagination flag
config.nextFlag = 0;
zim.queryBlacklist(config, new ZIMBlacklistQueriedCallback() {
@Override
public void onBlacklistQueried(ArrayList<ZIMUserInfo> blacklist, int nextFlag,
ZIMError zimError) {
if(errorInfo.code == ZIMErrorCode.SUCCESS) {
// Developers can get the blacklist from the blacklist.
}
}
});
1
// Query the blacklist
ZIMBlacklistQueryConfig config = ZIMBlacklistQueryConfig();
// Fill in the number of user information obtained at one time
config.count = 100;
// Fill in the paging pull flag
config.nextFlag = 0;
ZIM zim = ZIM.getInstance()!;
zim.queryBlacklist(config).then((ZIMBlacklistQueriedResult result) => {
// Developers can get the blacklist from result.blacklist.
}).catchError((onError){
// Handle according to the SDK error code document
});
1
// Query the blocklist.
ZIMBlacklistQueryConfig *config = [[ZIMBlacklistQueryConfig alloc] init];
// Enter the number of blocked users to be queried per time.
config.count = 100;
// Enter the flag for a paginated pull.
config.nextFlag = 0;
[[ZIM getInstance] queryBlacklistWithConfig:config callback:^(NSArray<ZIMUserInfo *> * _Nonnull blacklist, unsigned int nextFlag, ZIMError * _Nonnull errorInfo) {
if(errorInfo.code == ZIMErrorCodeSuccess){
// Obtain the blocklist from the `blacklist` field.
}
}];
1
// Query blacklist list
zim::ZIMBlacklistQueryConfig config;
// Fill in the number of blacklist user information obtained at one time
config.count = 100;
// Fill in the pagination pull flag
config.nextFlag = 0;
zim_sdk_->queryBlacklist(
config, [=](const std::vector<zim::ZIMUserInfo> &blacklist, unsigned int nextFlag,
const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIMErrorCode::ZIM_ERROR_CODE_SUCCESS) {
// Developers can get the blacklist list from blacklist.
}
});
1
Block Users
After logging in to the ZIM SDK, users can call the addUsersToBlacklistWithUserIDs interface to add specified users to the blacklist.
The result of blocking users is returned through the ZIMBlacklistUsersAddedCallback.
- Up to 20 users can be blocked with one API call. Exceeding the limit will cause the API call to fail.
- The default maximum number of blacklisted users is 1000. If you need to increase it, please contact ZEGOCLOUD technical support.
// Add user "zego" to the blacklist
ArrayList<String> userIDs = new ArrayList();
userIDs.add("zego");
zim.addUsersToBlacklist(userIDs, new ZIMBlacklistUsersAddedCallback() {
@Override
public void onBlacklistUsersAdded(ArrayList<ZIMErrorUserInfo> errorUserList, ZIMError error) {
if(errorInfo.code == ZIMErrorCode.SUCCESS) {
// errorUserList returns the information of users that failed to be added.
}
}
});
1
// Add user "zego" to the blacklist
try{
ZIMBlacklistUsersAddedResult result = await ZIM.getInstance()!.addUsersToBlacklist(['zego']);
// result.errorUserList returns the information of users that failed to be added.
} on PlatformException catch (onError){
// Handle according to the SDK error code document
}
1
// Block user "zegocloud".
NSArray *userIDs = @[@"zegocloud"];
[[ZIM getInstance] addUsersToBlacklistWithUserIDs:userIDs callback:^(NSArray<ZIMErrorUserInfo *> * _Nonnull errorUserList, ZIMError * _Nonnull errorInfo) {
if(errorInfo.code == ZIMErrorCodeSuccess){
// The information of users who fail to be blocked is returned in the `errorUserList` field.
}
}];
1
// Add user "zegocloud" to the blacklist
std::vector<std::string> user_id_list;
user_id_list.push_back("zegocloud");
zim_sdk_->addUsersToBlacklist(
user_id_list,
[=](const std::vector<zim::ZIMErrorUserInfo> &errorUserList, const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIMErrorCode::ZIM_ERROR_CODE_SUCCESS) {
// Developers can retrieve the blacklist from the "blacklist" variable.
}
});
1
Unblock Users
After logging in to the ZIM SDK, users can call the removeUsersFromBlacklistWithUserIDs interface to remove specified users from the blacklist.
The unblock operation will be returned through the ZIMBlacklistUsersRemovedCallback .
Up to 20 users can be removed with one API call. Exceeding the limit will cause the API call to fail.
// Remove user "zego" from the blacklist
ArrayList<String> userIDs = new ArrayList();
userIDs.add("zego");
zim.removeUsersFromBlacklist(userIDs, new ZIMBlacklistUsersRemovedCallback() {
@Override
public void onBlacklistUsersRemoved(ArrayList<ZIMErrorUserInfo> errorUserList, ZIMError error) {
if(errorInfo.code == ZIMErrorCode.SUCCESS) {
// errorUserList returns the information of users that failed to be removed.
}
}
});
1
// Remove user "zego" from the blacklist
try{
ZIMBlacklistUsersRemovedResult result = await ZIM.getInstance()!.removeUsersFromBlacklist(["zego"]);
// result.errorUserList returns the information of users that failed to be added.
} on PlatformException catch (onError){
// Handle according to the SDK error code document
}
1
// Unblock user "zegocloud".
NSArray *userIDs = @[@"zegocloud"];
[[ZIM getInstance] removeUsersFromBlacklistWithUserIDs:userIDs callback:^(NSArray<ZIMErrorUserInfo *> * _Nonnull errorUserList, ZIMError * _Nonnull errorInfo) {
if(errorInfo.code == ZIMErrorCodeSuccess){
// The information of users who fail to be unblocked is returned in the `errorUserList` field.
}
}];
1
// Remove user "zegocloud" from the blacklist
std::vector<std::string> user_id_list;
user_id_list.push_back("zegocloud");
zim_sdk_->removeUsersFromBlacklist(
user_id_list,
[=](const std::vector<zim::ZIMErrorUserInfo> &errorUserList, const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIMErrorCode::ZIM_ERROR_CODE_SUCCESS) {
// Developers can retrieve the blacklist from the "blacklist" variable.
}
});
1
Check if the user is in the blacklist
After logging in to the ZIM SDK, users can call the checkUserIsInBlackListByUserID interface to check if a specified user is in their blacklist.
The result of the check operation is returned through the ZIMBlacklistCheckedCallback.
// Check if the user "zego" is in the blacklist
zim.checkUserIsInBlackList("zego", new ZIMBlacklistCheckedCallback(){
@Override
public void onBlacklistChecked(boolean isUserInBlacklist, ZIMError zimError) {
if(errorInfo.code == ZIMErrorCode.SUCCESS) {
// isUserInBlacklist indicates whether the user is in the blacklist, true means in the blacklist, false means not in the blacklist
}
}
})
1
// Check if user "zego" is in the blacklist
try{
ZIMBlacklistCheckedResult result = await ZIM.getInstance()!.checkUserIsInBlacklist("zego");
// result.isUserInBlacklist indicates whether the user is in the blacklist. true means in the blacklist, false means not in the blacklist
} on PlatformException catch (onError){
// Handle according to the SDK error code document
}
1
// Check whether user "zegocloud" is in the blocklist.
[[ZIM getInstance] checkUserIsInBlackListByUserID:@"zegocloud" callback:^(BOOL isUserInBlacklist, ZIMError * _Nonnull errorInfo) {
if(errorInfo.code == ZIMErrorCodeSuccess) {
// The `isUserInBlacklist` parameter indicates whether the user is in the blocklist. Valid values: `true`: yes; `false`: no.
}
}];
1
zim_sdk_->checkUserIsInBlacklist(
"zegocloud", [=](bool isUserInBlacklist, const zim::ZIMError &errorInfo) {
if (errorInfo.code == zim::ZIMErrorCode::ZIM_ERROR_CODE_SUCCESS) {
// The `isUserInBlacklist` parameter indicates whether the user is in the blocklist. Valid values: `true`: yes; `false`: no.
}
});
1