tdlight/td/telegram/ReportReason.cpp

110 lines
4.2 KiB
C++
Raw Normal View History

2021-02-20 01:55:09 +01:00
//
2024-01-01 01:07:21 +01:00
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
2021-02-20 01:55:09 +01:00
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "td/telegram/ReportReason.h"
#include "td/telegram/misc.h"
namespace td {
Result<ReportReason> ReportReason::get_report_reason(td_api::object_ptr<td_api::ReportReason> reason,
2021-02-20 01:55:09 +01:00
string &&message) {
if (reason == nullptr) {
return Status::Error(400, "Chat report reason must be non-empty");
}
2021-02-20 01:55:09 +01:00
if (!clean_input_string(message)) {
return Status::Error(400, "Report text must be encoded in UTF-8");
}
auto type = [&] {
switch (reason->get_id()) {
case td_api::reportReasonSpam::ID:
2021-02-20 01:55:09 +01:00
return ReportReason::Type::Spam;
case td_api::reportReasonViolence::ID:
2021-02-20 01:55:09 +01:00
return ReportReason::Type::Violence;
case td_api::reportReasonPornography::ID:
2021-02-20 01:55:09 +01:00
return ReportReason::Type::Pornography;
case td_api::reportReasonChildAbuse::ID:
2021-02-20 01:55:09 +01:00
return ReportReason::Type::ChildAbuse;
case td_api::reportReasonCopyright::ID:
2021-02-20 01:55:09 +01:00
return ReportReason::Type::Copyright;
case td_api::reportReasonUnrelatedLocation::ID:
2021-02-20 01:55:09 +01:00
return ReportReason::Type::UnrelatedLocation;
case td_api::reportReasonFake::ID:
2021-02-20 01:55:09 +01:00
return ReportReason::Type::Fake;
case td_api::reportReasonIllegalDrugs::ID:
2022-02-18 14:12:39 +01:00
return ReportReason::Type::IllegalDrugs;
case td_api::reportReasonPersonalDetails::ID:
2022-02-18 14:12:39 +01:00
return ReportReason::Type::PersonalDetails;
case td_api::reportReasonCustom::ID:
2021-02-20 01:55:09 +01:00
return ReportReason::Type::Custom;
default:
UNREACHABLE();
return ReportReason::Type::Custom;
}
}();
return ReportReason(type, std::move(message));
}
tl_object_ptr<telegram_api::ReportReason> ReportReason::get_input_report_reason() const {
switch (type_) {
case ReportReason::Type::Spam:
return make_tl_object<telegram_api::inputReportReasonSpam>();
case ReportReason::Type::Violence:
return make_tl_object<telegram_api::inputReportReasonViolence>();
case ReportReason::Type::Pornography:
return make_tl_object<telegram_api::inputReportReasonPornography>();
case ReportReason::Type::ChildAbuse:
return make_tl_object<telegram_api::inputReportReasonChildAbuse>();
case ReportReason::Type::Copyright:
return make_tl_object<telegram_api::inputReportReasonCopyright>();
case ReportReason::Type::UnrelatedLocation:
return make_tl_object<telegram_api::inputReportReasonGeoIrrelevant>();
case ReportReason::Type::Fake:
return make_tl_object<telegram_api::inputReportReasonFake>();
2022-02-18 14:12:39 +01:00
case ReportReason::Type::IllegalDrugs:
return make_tl_object<telegram_api::inputReportReasonIllegalDrugs>();
case ReportReason::Type::PersonalDetails:
return make_tl_object<telegram_api::inputReportReasonPersonalDetails>();
2021-02-20 01:55:09 +01:00
case ReportReason::Type::Custom:
return make_tl_object<telegram_api::inputReportReasonOther>();
default:
UNREACHABLE();
return nullptr;
}
}
StringBuilder &operator<<(StringBuilder &string_builder, const ReportReason &report_reason) {
string_builder << "ReportReason";
switch (report_reason.type_) {
case ReportReason::Type::Spam:
return string_builder << "Spam";
case ReportReason::Type::Violence:
return string_builder << "Violence";
case ReportReason::Type::Pornography:
return string_builder << "Pornography";
case ReportReason::Type::ChildAbuse:
return string_builder << "ChildAbuse";
case ReportReason::Type::Copyright:
return string_builder << "Copyright";
case ReportReason::Type::UnrelatedLocation:
return string_builder << "UnrelatedLocation";
case ReportReason::Type::Fake:
return string_builder << "Fake";
2022-02-18 14:12:39 +01:00
case ReportReason::Type::IllegalDrugs:
return string_builder << "IllegalDrugs";
case ReportReason::Type::PersonalDetails:
return string_builder << "PersonalDetails";
2021-02-20 01:55:09 +01:00
case ReportReason::Type::Custom:
return string_builder << "Custom";
default:
UNREACHABLE();
}
return string_builder;
}
} // namespace td