diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 489d00e14..5aaacade7 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -606,6 +606,7 @@ PRIVATE data/data_replies_list.h data/data_reply_preview.cpp data/data_reply_preview.h + data/data_report.h data/data_saved_messages.cpp data/data_saved_messages.h data/data_saved_sublist.cpp diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 92d6976a9..27f71c9fc 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1662,6 +1662,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_report_and_ban_button" = "Ban user"; "lng_report_details_about" = "Please enter any additional details relevant to your report."; "lng_report_details" = "Additional Details"; +"lng_report_details_optional" = "Add Comment (Optional)"; +"lng_report_details_non_optional" = "Add Comment"; +"lng_report_details_message_about" = "Please help us by telling what is wrong with the message you have selected"; "lng_report_reason_spam" = "Spam"; "lng_report_reason_fake" = "Fake Account"; "lng_report_reason_violence" = "Violence"; diff --git a/Telegram/SourceFiles/api/api_report.cpp b/Telegram/SourceFiles/api/api_report.cpp index 869152737..dd0582779 100644 --- a/Telegram/SourceFiles/api/api_report.cpp +++ b/Telegram/SourceFiles/api/api_report.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "data/data_peer.h" #include "data/data_photo.h" +#include "data/data_report.h" #include "data/data_user.h" #include "lang/lang_keys.h" #include "main/main_session.h" @@ -40,15 +41,11 @@ MTPreportReason ReasonToTL(const Ui::ReportReason &reason) { } // namespace void SendReport( - std::shared_ptr show, - not_null peer, - Ui::ReportReason reason, - const QString &comment, - std::variant< - v::null_t, - MessageIdsList, - not_null, - StoryId> data) { + std::shared_ptr show, + not_null peer, + Ui::ReportReason reason, + const QString &comment, + std::variant> data) { auto done = [=] { show->showToast(tr::lng_report_thanks(tr::now)); }; @@ -58,18 +55,6 @@ void SendReport( ReasonToTL(reason), MTP_string(comment) )).done(std::move(done)).send(); - }, [&](const MessageIdsList &ids) { - 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(std::move(done)).send(); }, [&](not_null photo) { peer->session().api().request(MTPaccount_ReportProfilePhoto( peer->input, @@ -77,14 +62,93 @@ void SendReport( ReasonToTL(reason), MTP_string(comment) )).done(std::move(done)).send(); - }, [&](StoryId id) { - peer->session().api().request(MTPstories_Report( - peer->input, - MTP_vector(1, MTP_int(id)), - ReasonToTL(reason), - MTP_string(comment) - )).done(std::move(done)).send(); }); } +auto CreateReportMessagesOrStoriesCallback( + std::shared_ptr show, + not_null peer) +-> Fn)> { + using TLChoose = MTPDreportResultChooseOption; + using TLAddComment = MTPDreportResultAddComment; + using TLReported = MTPDreportResultReported; + using Result = ReportResult; + + struct State final { +#ifdef _DEBUG + ~State() { + qDebug() << "Messages or Stories Report ~State()."; + } +#endif + mtpRequestId requestId = 0; + }; + const auto state = std::make_shared(); + + return [=]( + Data::ReportInput reportInput, + Fn done) { + auto apiIds = QVector(); + apiIds.reserve(reportInput.ids.size() + reportInput.stories.size()); + for (const auto &id : reportInput.ids) { + apiIds.push_back(MTP_int(id)); + } + for (const auto &story : reportInput.stories) { + apiIds.push_back(MTP_int(story)); + } + + const auto received = [=]( + const MTPReportResult &result, + mtpRequestId requestId) { + if (state->requestId != requestId) { + return; + } + state->requestId = 0; + done(result.match([&](const TLChoose &data) { + const auto t = qs(data.vtitle()); + auto list = Result::Options(); + list.reserve(data.voptions().v.size()); + for (const auto &tl : data.voptions().v) { + list.emplace_back(Result::Option{ + .id = tl.data().voption().v, + .text = qs(tl.data().vtext()), + }); + } + return Result{ .options = std::move(list), .title = t }; + }, [&](const TLAddComment &data) -> Result { + return { + .commentOption = ReportResult::CommentOption{ + .optional = data.is_optional(), + .id = data.voption().v, + } + }; + }, [&](const TLReported &data) -> Result { + return { .successful = true }; + })); + }; + + const auto fail = [=](const MTP::Error &error) { + state->requestId = 0; + done({ .error = error.type() }); + }; + + if (!reportInput.stories.empty()) { + state->requestId = peer->session().api().request( + MTPstories_Report( + peer->input, + MTP_vector(apiIds), + MTP_bytes(reportInput.optionId), + MTP_string(reportInput.comment)) + ).done(received).fail(fail).send(); + } else { + state->requestId = peer->session().api().request( + MTPmessages_Report( + peer->input, + MTP_vector(apiIds), + MTP_bytes(reportInput.optionId), + MTP_string(reportInput.comment)) + ).done(received).fail(fail).send(); + } + }; +} + } // namespace Api diff --git a/Telegram/SourceFiles/api/api_report.h b/Telegram/SourceFiles/api/api_report.h index 14e9d4ef1..f0c0320f3 100644 --- a/Telegram/SourceFiles/api/api_report.h +++ b/Telegram/SourceFiles/api/api_report.h @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +class HistoryItem; class PeerData; class PhotoData; @@ -15,17 +16,41 @@ class Show; enum class ReportReason; } // namespace Ui +namespace Data { +struct ReportInput; +} // namespace Data + namespace Api { +struct ReportResult final { + using Id = QByteArray; + struct Option final { + Id id = 0; + QString text; + }; + using Options = std::vector