logo
On this page

Blacklist management


Note

Blacklisting and friend operations do not affect each other. Taking user A and B as friends as an example:

  1. User A can blacklist user B, but they will still be friends.
  2. If at this point, user A and user B end their friendship, user B will still be on user A's blacklist.
  3. 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 queryBlacklist interface.

The query result is returned through ZIMBlacklistQueriedResult.

Sample code
// Query the blacklist
zim.queryBlacklist({ count: 100, nextFlag: 0 }).then(res => {
    const blacklist = res.blacklist;
})
1
Copied!

Block Users

After logging in to the ZIM SDK, users can call the addUsersToBlacklist interface to add specified users to the blacklist.

The result of blocking users is returned through the ZIMBlacklistUsersAddedResult.

Warning
  • 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.
Sample code
// Add user "zego" to the blacklist
const userIDs = ['zego'];
zim.addUsersToBlacklist(userIDs).then(res => {
    // Added successfully
});
1
Copied!

Unblock Users

After logging in to the ZIM SDK, users can call the removeUsersFromBl interface to remove specified users from the blacklist.

The unblock operation will be returned through the ZIMBlacklistUsersRemovedResult.

Warning

Up to 20 users can be removed with one API call. Exceeding the limit will cause the API call to fail.

Sample code
// Remove user "zego" from the blacklist
const userIDs = ['zego'];
zim.removeUsersFromBlacklist(userIDs).then(res => {
    // Removed successfully
});
1
Copied!

Check if the user is in the blacklist

After logging in to the ZIM SDK, users can call the checkUserIsInBlacklist interface to check if a specified user is in their blacklist.

The result of the check operation is returned through the ZIMBlacklistCheckedResult.

title=
// Check if user "zego" is in the blacklist
zim.checkUserIsInBlacklist('zego').then(res => {
    const isUserInBlacklist = res.isUserInBlacklist;
});
1
Copied!

Previous

Offline login

Next

Friend management