SDKsuni-app
搜索好友
按用户 ID、昵称或备注搜索当前好友。
searchFriends() 只搜索当前好友关系,不是全站用户搜索。通过布尔字段明确要匹配的属性。
当前建议只使用一个去除首尾空格后的非空关键词。空关键词应在调用前拦截。
参数说明
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
keywordList | string[] | 是 | 搜索关键词数组;当前只使用第一个非空关键词。 |
isSearchUserID | boolean | 是 | 是否匹配好友用户 ID。 |
isSearchNickname | boolean | 是 | 是否匹配好友昵称。 |
isSearchRemark | boolean | 是 | 是否匹配当前用户设置的好友备注。 |
import { searchFriends } from '@/uni_modules/unix-openim-sdk'
const result = await searchFriends({
keywordList: ['Alice'],
isSearchUserID: true,
isSearchNickname: true,
isSearchRemark: true,
})
renderFriends(result?.friends ?? [])Promise 成功后直接返回 OpenIMFriendListResult | null,从 friends 读取 OpenIMFriendUserItem[]。好友字段见分页获取好友列表。
搜索结果只建立当前条件下的展示快照,不改变好友资料或服务端索引,也不应覆盖完整好友列表。按 userID 关联现有好友状态,并继续合并好友事件;需要查指定好友资料时使用查询指定好友资料。
这个页面有帮助吗?