searchFriends static method
Future<V2TimValueCallback<List<V2TimFriendInfoResult> > >
searchFriends({
- required V2TimFriendSearchParam searchParam,
Implementation
static Future<V2TimValueCallback<List<V2TimFriendInfoResult>>> searchFriends({
required V2TimFriendSearchParam searchParam,
}) async {
List<int> search_field_list = List.empty(growable: true);
if (searchParam.isSearchNickName) {
search_field_list.add(0x01 << 1);
}
if (searchParam.isSearchRemark) {
search_field_list.add(0x01 << 2);
}
if (searchParam.isSearchUserID) {
search_field_list.add(0x01);
}
String param = json.encode(Map<String, dynamic>.from({
"friendship_search_param_keyword_list": searchParam.keywordList,
"friendship_search_param_search_field_list": search_field_list,
}));
String userData = Tools.generateUserData();
Pointer<Uint8> user_data = Tools.string2PointerInt8(userData);
Pointer<Uint8> json_search_friends_param = Tools.string2PointerInt8(param);
int res = desktopSDK.D_TIMFriendshipSearchFriends(json_search_friends_param, user_data);
if (res != TIMResult.TIM_SUCC) {
return V2TimValueCallback<List<V2TimFriendInfoResult>>.fromJson({
"code": res,
"desc": "",
});
} else {
Map<String, dynamic> data = await getAsyncData(apiKey: userData);
List<Map<String, dynamic>> listData = List<Map<String, dynamic>>.from(json.decode(data["json_param"].isEmpty ? json.encode([]) : data["json_param"]));
List<Map<String, dynamic>> dartListData = List<Map<String, dynamic>>.empty(growable: true);
for (var element in listData) {
Map<String, dynamic> nativeJson = Map<String, dynamic>.from(element);
Map<String, dynamic> dartJson = Map<String, dynamic>.from({
"resultCode": nativeJson["friendship_friend_info_get_result_error_code"],
"resultInfo": nativeJson["friendship_friend_info_get_result_error_message"],
"relation": nativeJson["friendship_friend_info_get_result_relation_type"],
"friendInfo": Tools.friendProfile2DartFriendInfo(nativeJson["friendship_friend_info_get_result_field_info"]).toJson()
});
dartListData.add(dartJson);
}
return V2TimValueCallback<List<V2TimFriendInfoResult>>.fromJson({"code": data["code"], "desc": data["desc"], "data": dartListData});
}
}