Browse SDKs · React Native
SDKsReact Native

Get the blacklist

Get the blocklist with the OpenIM React Native SDK.

Copy

Call getBlackList() to get the current account's blocklist.

const blockedUsers = await OpenIMSDK.getBlackList();

The method returns BlackUserItem[]:

FieldTypeDescription
userIDstringID of the blocked user.
nicknamestringNickname of the blocked user.
faceURLstringAvatar URL of the blocked user.
ownerUserIDstringUser ID that owns the blocklist relationship.
operatorUserIDstringUser ID that performed the block operation.
createTimenumberTime when the blocklist record was created.
addSourcenumberSource from which the user was blocked.
exstringBlocklist extension field.

Use userID when checking a blocklist relationship in a profile card or contact list. Blocklist management is separate from group management; use group APIs for muting or removing group members.

Listen for blocklist changes

When the blocklist changes, OnBlackAdded or OnBlackDeleted is emitted with the corresponding blocked-user information:

const handleBlackAdded = (blackUser: BlackUserItem) => {
  // Add or update the record by blackUser.userID
};
const handleBlackDeleted = (blackUser: BlackUserItem) => {
  // Remove the record by blackUser.userID
};

OpenIMSDK.on(OpenIMEvent.OnBlackAdded, handleBlackAdded);
OpenIMSDK.on(OpenIMEvent.OnBlackDeleted, handleBlackDeleted);

OpenIMSDK.off(OpenIMEvent.OnBlackAdded, handleBlackAdded);
OpenIMSDK.off(OpenIMEvent.OnBlackDeleted, handleBlackDeleted);

Remove these listeners when logging out, switching accounts, or tearing down the blocklist state.