refuseGroupApplication static method

Future<V2TimCallback> refuseGroupApplication({
  1. required String groupID,
  2. String? reason,
  3. required String fromUser,
  4. required String toUser,
  5. int? addTime,
  6. int? type,
  7. String? webMessageInstance,
})

Implementation

static Future<V2TimCallback> refuseGroupApplication({
  required String groupID,
  String? reason,
  required String fromUser,
  required String toUser,
  int? addTime,
  int? type,
  String? webMessageInstance,
}) async {
  if (addTime == null) {
    return V2TimCallback.fromJson({
      "code": "-3",
      "desc": "add time is required",
    });
  }
  String mapKey = "$fromUser-$toUser-$addTime";

  if (!groupAuth.containsKey(mapKey)) {
    return V2TimCallback.fromJson({
      "code": "-3",
      "desc": "this application is no need refuse",
    });
  }
  String auth = groupAuth.remove(mapKey) ?? "";
  String key = groupAuthKey.remove(mapKey) ?? "";

  V2TimValueCallback<String> userres = await getLoginUser();
  String currentLoginUser = "";
  if (userres.code == 0) {
    if (userres.data != null) {
      if (userres.data!.isNotEmpty) {
        currentLoginUser = userres.data!;
      }
    }
  }
  if (currentLoginUser.isEmpty) {
    return V2TimCallback.fromJson({
      "code": "-3",
      "desc": "get current login user failed",
    });
  }

  String param = json.encode({
    "group_handle_pendency_param_is_accept": false,
    "group_handle_pendency_param_handle_msg": reason,
    "group_handle_pendency_param_pendency": Map.from({
      "group_pendency_group_id": groupID,
      "group_pendency_form_identifier": fromUser,
      "group_pendency_to_identifier": toUser,
      "group_pendency_authentication": auth,
      "group_pendency_pendency_type": type,
      "group_pendency_key": key,
      "group_pendency_self_identifier": currentLoginUser,
    })
  });
  String userData = Tools.generateUserData();
  Pointer<Uint8> user_data = Tools.string2PointerInt8(userData);
  Pointer<Uint8> json_group_handle_pendency_param = Tools.string2PointerInt8(param);
  int res = desktopSDK.D_TIMGroupHandlePendency(json_group_handle_pendency_param, user_data);
  if (res != TIMResult.TIM_SUCC) {
    return V2TimCallback.fromJson({
      "code": res,
      "desc": "",
    });
  } else {
    Map<String, dynamic> data = await getAsyncData(apiKey: userData);
    return V2TimCallback.fromJson({
      "code": data["code"],
      "desc": data["desc"],
    });
  }
}