From 6dce8dfa200cf01d0073c645928d27cbe8876e59 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 17 Apr 2022 13:16:48 +0300 Subject: [PATCH] Moved api for report messages to separated file. --- Telegram/CMakeLists.txt | 2 + Telegram/SourceFiles/api/api_report.cpp | 70 +++++++++++++++++++ Telegram/SourceFiles/api/api_report.h | 24 +++++++ .../SourceFiles/history/history_widget.cpp | 3 +- .../view/history_view_context_menu.cpp | 52 +------------- .../history/view/history_view_context_menu.h | 5 -- 6 files changed, 101 insertions(+), 55 deletions(-) create mode 100644 Telegram/SourceFiles/api/api_report.cpp create mode 100644 Telegram/SourceFiles/api/api_report.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 2caed21170..5649410b65 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -137,6 +137,8 @@ PRIVATE api/api_peer_photo.h api/api_polls.cpp api/api_polls.h + api/api_report.cpp + api/api_report.h api/api_ringtones.cpp api/api_ringtones.h api/api_self_destruct.cpp diff --git a/Telegram/SourceFiles/api/api_report.cpp b/Telegram/SourceFiles/api/api_report.cpp new file mode 100644 index 0000000000..9238db1fa5 --- /dev/null +++ b/Telegram/SourceFiles/api/api_report.cpp @@ -0,0 +1,70 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "api/api_report.h" + +#include "apiwrap.h" +#include "data/data_peer.h" +#include "lang/lang_keys.h" +#include "main/main_session.h" +#include "ui/boxes/report_box.h" +#include "ui/toast/toast.h" + +namespace Api { + +namespace { + +MTPreportReason ReasonToTL(const Ui::ReportReason &reason) { + using Reason = Ui::ReportReason; + switch (reason) { + case Reason::Spam: return MTP_inputReportReasonSpam(); + case Reason::Fake: return MTP_inputReportReasonFake(); + case Reason::Violence: return MTP_inputReportReasonViolence(); + case Reason::ChildAbuse: return MTP_inputReportReasonChildAbuse(); + case Reason::Pornography: return MTP_inputReportReasonPornography(); + case Reason::Copyright: return MTP_inputReportReasonCopyright(); + case Reason::IllegalDrugs: return MTP_inputReportReasonIllegalDrugs(); + case Reason::PersonalDetails: + return MTP_inputReportReasonPersonalDetails(); + case Reason::Other: return MTP_inputReportReasonOther(); + } + Unexpected("Bad reason group value."); +} + +} // namespace + +void SendReport( + not_null peer, + Ui::ReportReason reason, + const QString &comment, + MessageIdsList ids) { + if (ids.empty()) { + peer->session().api().request(MTPaccount_ReportPeer( + peer->input, + ReasonToTL(reason), + MTP_string(comment) + )).done([=] { + Ui::Toast::Show(tr::lng_report_thanks(tr::now)); + }).send(); + } else { + auto apiIds = QVector(); + apiIds.reserve(ids.size()); + for (const auto &fullId : ids) { + apiIds.push_back(MTP_int(fullId.msg)); + } + peer->session().api().request(MTPmessages_Report( + peer->input, + MTP_vector(apiIds), + ReasonToTL(reason), + MTP_string(comment) + )).done([=] { + Ui::Toast::Show(tr::lng_report_thanks(tr::now)); + }).send(); + } +} + +} // namespace Api diff --git a/Telegram/SourceFiles/api/api_report.h b/Telegram/SourceFiles/api/api_report.h new file mode 100644 index 0000000000..cfe7d80b7a --- /dev/null +++ b/Telegram/SourceFiles/api/api_report.h @@ -0,0 +1,24 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +class PeerData; + +namespace Ui { +enum class ReportReason; +} // namespace Ui + +namespace Api { + +void SendReport( + not_null peer, + Ui::ReportReason reason, + const QString &comment, + MessageIdsList ids = {}); + +} // namespace Api diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 844e346755..2625691d86 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_editing.h" #include "api/api_bot.h" #include "api/api_chat_participants.h" +#include "api/api_report.h" #include "api/api_sending.h" #include "api/api_text_entities.h" #include "api/api_send_progress.h" @@ -3884,7 +3885,7 @@ void HistoryWidget::reportSelectedMessages() { clearSelected(); controller()->clearChooseReportMessages(); } - HistoryView::SendReport(peer, reason, text, ids); + Api::SendReport(peer, reason, text, ids); box->closeBox(); }); })); diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index b18a1990b9..c471be3edd 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_attached_stickers.h" #include "api/api_editing.h" #include "api/api_polls.h" +#include "api/api_report.h" #include "api/api_ringtones.h" #include "api/api_who_reacted.h" #include "api/api_toggling_media.h" // Api::ToggleFavedSticker @@ -1207,7 +1208,7 @@ void ShowWhoReactedMenu( void ShowReportItemsBox(not_null peer, MessageIdsList ids) { const auto chosen = [=](Ui::ReportReason reason) { Ui::show(Box(Ui::ReportDetailsBox, [=](const QString &text) { - SendReport(peer, reason, text, ids); + Api::SendReport(peer, reason, text, ids); Ui::hideLayer(); })); }; @@ -1229,7 +1230,7 @@ void ShowReportPeerBox( const auto chosen = [=](Ui::ReportReason reason) { const auto send = [=](const QString &text) { window->clearChooseReportMessages(); - SendReport(peer, reason, text, std::move(state->ids)); + Api::SendReport(peer, reason, text, std::move(state->ids)); if (const auto strong = state->reasonBox.data()) { strong->closeBox(); } @@ -1261,51 +1262,4 @@ void ShowReportPeerBox( chosen)); } -void SendReport( - not_null peer, - Ui::ReportReason reason, - const QString &comment, - MessageIdsList ids) { - const auto apiReason = [&] { - using Reason = Ui::ReportReason; - switch (reason) { - case Reason::Spam: return MTP_inputReportReasonSpam(); - case Reason::Fake: return MTP_inputReportReasonFake(); - case Reason::Violence: return MTP_inputReportReasonViolence(); - case Reason::ChildAbuse: return MTP_inputReportReasonChildAbuse(); - case Reason::Pornography: return MTP_inputReportReasonPornography(); - case Reason::Copyright: return MTP_inputReportReasonCopyright(); - case Reason::IllegalDrugs: - return MTP_inputReportReasonIllegalDrugs(); - case Reason::PersonalDetails: - return MTP_inputReportReasonPersonalDetails(); - case Reason::Other: return MTP_inputReportReasonOther(); - } - Unexpected("Bad reason group value."); - }(); - if (ids.empty()) { - peer->session().api().request(MTPaccount_ReportPeer( - peer->input, - apiReason, - MTP_string(comment) - )).done([=] { - Ui::Toast::Show(tr::lng_report_thanks(tr::now)); - }).send(); - } else { - auto apiIds = QVector(); - apiIds.reserve(ids.size()); - for (const auto &fullId : ids) { - apiIds.push_back(MTP_int(fullId.msg)); - } - peer->session().api().request(MTPmessages_Report( - peer->input, - MTP_vector(apiIds), - apiReason, - MTP_string(comment) - )).done([=] { - Ui::Toast::Show(tr::lng_report_thanks(tr::now)); - }).send(); - } -} - } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.h b/Telegram/SourceFiles/history/view/history_view_context_menu.h index 03d7b3c455..dab8c4ff62 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.h +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.h @@ -83,10 +83,5 @@ void ShowReportItemsBox(not_null peer, MessageIdsList ids); void ShowReportPeerBox( not_null window, not_null peer); -void SendReport( - not_null peer, - Ui::ReportReason reason, - const QString &comment, - MessageIdsList ids = {}); } // namespace HistoryView