addFriend static method
Future<V2TimValueCallback<V2TimFriendOperationResult>>
addFriend(
{ - required String userID,
- String? friendGroup,
- String? addWording,
- String? addSource,
- required int addType,
})
Implementation
static Future<V2TimValueCallback<V2TimFriendOperationResult>> addFriend({
required String userID,
String? remark,
String? friendGroup,
String? addWording,
String? addSource,
required int addType,
}) async {
String param = json.encode({
"friendship_add_friend_param_identifier": userID,
"friendship_add_friend_param_friend_type": addType - 1, // 这里有点神奇,和native不一样
"friendship_add_friend_param_remark": remark,
"friendship_add_friend_param_add_source": addSource,
"friendship_add_friend_param_add_wording": addWording,
"friendship_add_friend_param_group_name": friendGroup,
});
String userData = Tools.generateUserData();
Pointer<Uint8> user_data = Tools.string2PointerInt8(userData);
Pointer<Uint8> json_add_friend_param = Tools.string2PointerInt8(param);
int res = desktopSDK.D_TIMFriendshipAddFriend(json_add_friend_param, user_data);
if (res != TIMResult.TIM_SUCC) {
return V2TimValueCallback<V2TimFriendOperationResult>.fromJson({
"code": res,
"desc": "",
});
} else {
Map<String, dynamic> data = await getAsyncData(apiKey: userData);
Map<String, dynamic> nativeJson = Map<String, dynamic>.from(json.decode(data["json_param"].isEmpty ? json.encode({}) : data["json_param"]));
Map<String, dynamic> dartJson = Map<String, dynamic>.from({
"resultCode": nativeJson["friend_result_code"],
"resultInfo": nativeJson["friend_result_desc"],
"userID": nativeJson["friend_result_identifier"],
});
return V2TimValueCallback<V2TimFriendOperationResult>.fromJson({"code": data["code"], "desc": data["desc"], "data": dartJson});
}
}