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 同时包含 friend 和 relationship。搜索结果只代表本次匹配,不应覆盖完整好友列表;使用 friend.friendUserID 与缓存对应。查询不会触发好友事件。
这个页面有帮助吗?