Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Search friends

Search friends locally by user ID, nickname, or remark note.

Copy

Trim leading and trailing whitespace from the search keyword, and enable at least one matching dimension:

Code example

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

const request: SearchFriendsReq = {
  keyword: keyword.trim(),
  searchUserID: true,
  searchNickname: true,
  searchRemark: true,
};
const response: SearchFriendsResp = await sdk.searchFriends(request);
showSearchResults(response.friends);

Parameters

ParameterTypeRequiredDescription
keywordstringYesSearch query string.
searchUserIDbooleanYesWhether to match user IDs.
searchNicknamebooleanYesWhether to match public nicknames.
searchRemarkbooleanYesWhether to match private friend remarks.

Return value

Returns a Promise that resolves to a SearchFriendsResp object containing friends: SearchFriendsInfo[]:

PropertyTypeDescription
friendIMFriendMatched friend relationship object.
relationshipnumberNumerical indicator representing relationship type.

State changes after the call

Search results represent filtered views and must not overwrite the baseline friend cache loaded via Paginate friend list. Correlate results with cached items using friend.friendUserID. This query runs locally and does not emit events.