SDKsReact Native
Get the blacklist
Get the blocklist with the OpenIM React Native SDK.
Call getBlackList() to get the current account's blocklist.
const blockedUsers = await OpenIMSDK.getBlackList();The method returns BlackUserItem[]:
| Field | Type | Description |
|---|---|---|
userID | string | ID of the blocked user. |
nickname | string | Nickname of the blocked user. |
faceURL | string | Avatar URL of the blocked user. |
ownerUserID | string | User ID that owns the blocklist relationship. |
operatorUserID | string | User ID that performed the block operation. |
createTime | number | Time when the blocklist record was created. |
addSource | number | Source from which the user was blocked. |
ex | string | Blocklist 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.
Was this page helpful?