浏览 SDKs · HarmonyOS
平台
SDKsHarmonyOS商业版

搜索好友

按用户 ID、昵称或好友备注搜索当前用户的好友。

复制

提交前去除关键词首尾空格,并至少启用一种匹配方式。

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);

返回的 SearchFriendsInfo 同时包含 friendrelationship。搜索结果只代表本次匹配,不应覆盖完整好友列表;使用 friend.friendUserID 与缓存对应。查询不会触发好友事件。