addFriend method

  1. @override
Future<V2TimValueCallback<V2TimFriendOperationResult>> addFriend({
  1. required String userID,
  2. required FriendTypeEnum addType,
  3. String? remark,
  4. String? friendGroup,
  5. String? addSource,
  6. String? addWording,
})
override

Implementation

@override
Future<V2TimValueCallback<V2TimFriendOperationResult>> addFriend({
  required String userID,
  required FriendTypeEnum addType,
  String? remark,
  String? friendGroup,
  String? addSource,
  String? addWording,
}) async {
  final result =
      await TencentImSDKPlugin.v2TIMManager.getFriendshipManager().addFriend(
            userID: userID,
            addType: addType,
            remark: remark,
            addWording: addWording,
            friendGroup: friendGroup,
            addSource: addSource,
          );
  if (result.code != 0) {
    _coreService.callOnCallback(TIMCallback(
      type: TIMCallbackType.API_ERROR,
      errorMsg: result.desc,
      errorCode: result.code,
      infoRecommendText: TIM_t("好友添加失败"),
    ));
  } else if (result.code == 0 && result.data?.resultCode != 0) {
    String recommendText = "";
    if (result.data != null && result.data!.resultCode != null) {
      recommendText = ErrorMessageConverter.getErrorMessage(result.data!.resultCode!);
    }

    _coreService.callOnCallback(TIMCallback(
      type: TIMCallbackType.API_ERROR,
      errorMsg: result.code == 0 ? result.data?.resultInfo : result.desc,
      errorCode: result.code == 0 ? result.data?.resultCode : result.code,
      infoRecommendText: recommendText,
    ));
  } else {
    _coreService.callOnCallback(TIMCallback(
        type: TIMCallbackType.API_ERROR,
        errorMsg: result.desc,
        errorCode: result.code,
        infoRecommendText: TIM_t("好友添加成功"),
    ));
  }

  return result;
}