Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Add user to blocklist

Add a designated user to the current account’s blocklist.

Copy

Block a specific user ID to prevent unwanted contact:

Code example

import sdk, { AddBlackReq } from '@openimsdk/imsdk';

const request: AddBlackReq = {
  userID: targetUserID,
  ex: '',
};
await sdk.addBlack(request);

Parameters

ParameterTypeRequiredDescription
userIDstringYesTarget user identifier to block.
exstringNoCustom application metadata string.

Return value

Returns a Promise that resolves to void upon saving the blocklist record on the server.

State changes after the call

Resolving the Promise initiates the blocklist update. Correlate local blocklist records using blockUserID (matching the target userID) when EventOnBlackAdded arrives; see Retrieve blocklist for listener patterns. Adding a user to the blocklist does not automatically purge chat history; manage conversation visibility separately in application code.