reportMessages method

FutureOr<Map> reportMessages({
  1. required Map parameters,
  2. required TelegramClientCallApiInvoke callApiInvoke,
})

method ReportMessages

Implementation

FutureOr<Map> reportMessages({
  required Map parameters,
  required TelegramClientCallApiInvoke callApiInvoke,
}) async {
  dynamic target_chat_id = TgUtils.parse_all_chat_id(parameters: parameters);
  if (target_chat_id is String &&
      RegExp(r"^((@)[a-z0-9_]+)$", caseSensitive: false)
          .hashData(target_chat_id)) {
    var search_public_chat = await callApiInvoke(
      parameters: {
        "@type": "searchPublicChat",
        "username": (target_chat_id)
            .replaceAll(RegExp(r"@", caseSensitive: false), ""),
      },
      is_invoke_no_relevance: true,
    );
    if (search_public_chat["@type"] == "chat") {
      parameters["chat_id"] = search_public_chat["id"];
    } else {
      return search_public_chat;
    }
  }
  Map request_parameters = {
    "@type": "reportChat",
    "chat_id": parameters["chat_id"],
    "message_ids": (parameters["message_ids"] as List)
        .map((e) => TgUtils.messageApiToTdlib(e))
        .toList(),
    "reason": {
      "@type": "reportReasonCustom",
    },
  };
  String reason_report = () {
    if (parameters["reason"] is String) {
      return (parameters["reason"] as String).toLowerCase();
    }
    return "";
  }();

  if (reason_report == "child_abuse") {
    request_parameters["reason"]["@type"] = "reportReasonChildAbuse";
  }

  if (reason_report == "copyright") {
    request_parameters["reason"]["@type"] = "reportReasonCopyright";
  }

  if (reason_report == "custom") {
    request_parameters["reason"]["@type"] = "reportReasonCustom";
  }

  if (reason_report == "fake") {
    request_parameters["reason"]["@type"] = "reportReasonFake";
  }

  if (reason_report == "illegal_drugs") {
    request_parameters["reason"]["@type"] = "reportReasonIllegalDrugs";
  }
  if (reason_report == "personal_details") {
    request_parameters["reason"]["@type"] = "reportReasonPersonalDetails";
  }
  if (reason_report == "porn") {
    request_parameters["reason"]["@type"] = "reportReasonPornography";
  }
  if (reason_report == "spam") {
    request_parameters["reason"]["@type"] = "reportReasonSpam";
  }
  if (reason_report == "unrelated_location") {
    request_parameters["reason"]["@type"] = "reportReasonUnrelatedLocation";
  }
  if (reason_report == "violence") {
    request_parameters["reason"]["@type"] = "reportReasonViolence";
  }
  if (parameters["text"] is String) {
    request_parameters["text"] = parameters["text"];
  }
  Map request_result = await callApiInvoke(
    parameters: request_parameters,
  );
  return request_result;
}