即时通信 IM Flutter(搜索好友)

这篇说说腾讯云IM Flutter SDK的本地用户资料搜索功能,用户只能搜索已拉取过的好友或用户,通过searchFriends接口可设置关键词并指定搜索昵称、备注或ID字段。 搜索范围:仅限本地已存储的用户资料,如好友列表和已拉取的用户信息。 接口说明:searchFriends支持keywordList关键词(最多5个)及isSearchNickName等搜索范围参数。

相关产品
即时通信 IM 产品页,含版本规格、价格与购买入口。

一、功能描述

用户搜索只能搜索本地存储过的用户,例如拉取过的好友列表,拉取过的用户资料等。

注意:说明:

注意:Flutter SDK 3.8.0支持。

二、搜索本地用户资料

调用接口 searchFriends (点击查看详情) 可以搜索本地用户资料。

你可以设置搜索关键字 keywordList,并指定搜索的范围,即是否搜索用户的 userID、nickName、remark 字段。

示例代码如下:

// 通过关键词搜索好友 //搜索好友的搜索条件 V2TimFriendSearchParam searchParam = V2TimFriendSearchParam( isSearchNickName: true,//是否搜索昵称 isSearchRemark: true,//是否搜索备注 isSearchUserID: true,//是否搜索id keywordList: [],//关键字列表,最多支持5个。 ); V2TimValueCallback<List<V2TimFriendInfoResult>> searchFriendsRes = await TencentImSDKPlugin.v2TIMManager .getFriendshipManager() .searchFriends(searchParam: searchParam); //搜索好友的搜索条件 if (searchFriendsRes.code == 0) { // 查询成功 searchFriendsRes.data?.forEach((element) { element.relation; //好友类型 0:不是好友 1:对方在我的好友列表中 2:我在对方的好友列表中 3:互为好友 element.resultCode; //此条记录的查询结果错误码 element.resultInfo; //此条查询结果描述 //friendInfo为好友个人资料,如果不是好友,除了 userID 字段,其他字段都为空 element.friendInfo ?.friendCustomInfo; //好友自定义字段 首先要在 控制台 (功能配置 -> 好友自定义字段) 配置好友自定义字段,然后再调用接口进行设置 element.friendInfo?.friendGroups; //好友所在分组列表 element.friendInfo?.friendRemark; //好友备注 element.friendInfo?.userID; //用户的id element.friendInfo?.userProfile ?.allowType; //用户的好友验证方式 0:允许所有人加我好友 1:不允许所有人加我好友 2:加我好友需我确认 element.friendInfo?.userProfile?.birthday; //用户生日 element.friendInfo?.userProfile?.customInfo; //用户的自定义状态 element.friendInfo?.userProfile?.faceUrl; //用户头像 url element.friendInfo?.userProfile?.gender; //用户的性别 1:男 2:女 element.friendInfo?.userProfile?.level; //用户的等级 element.friendInfo?.userProfile?.nickName; //用户昵称 element.friendInfo?.userProfile?.role; //用户的角色 element.friendInfo?.userProfile?.selfSignature; //用户的签名 element.friendInfo?.userProfile?.userID; //用户 ID }); }

赞 (0)
上一篇 4天前
下一篇 4天前