SDKsHarmonyOSEnterprise
Search friends
Search friends locally by user ID, nickname, or remark note.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
keyword | string | Yes | Search query string. |
searchUserID | boolean | Yes | Whether to match user IDs. |
searchNickname | boolean | Yes | Whether to match public nicknames. |
searchRemark | boolean | Yes | Whether to match private friend remarks. |
Return value
Returns a Promise that resolves to a SearchFriendsResp object containing friends: SearchFriendsInfo[]:
| Property | Type | Description |
|---|---|---|
friend | IMFriend | Matched friend relationship object. |
relationship | number | Numerical 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.
Was this page helpful?