diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index d198a8be6..d0c8c8a9b 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1575,6 +1575,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_report_button" = "Report"; "lng_report_thanks" = "Thank you! Your report will be reviewed by our team very soon."; +"lng_report_sponsored_hidden" = "Sponsored messages will be hidden."; +"lng_report_sponsored_reported" = "We will review this ad to ensure it matches out {link}."; +"lng_report_sponsored_reported_link" = "Ad Policies and Guidelines"; + "lng_channel_add_members" = "Add members"; "lng_channel_add_users" = "Add users"; "lng_channel_add_removed" = "Remove user"; @@ -4657,6 +4661,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_sponsored_info_menu" = "About this ad"; "lng_sponsored_info_submenu" = "Advertiser: {text}"; "lng_sponsored_menu_revenued_about" = "About These Ads"; +"lng_sponsored_menu_revenued_report" = "Report Ad"; "lng_sponsored_revenued_subtitle" = "Telegram Ads are very different from ads on other platforms. Ads such as this one:"; "lng_sponsored_revenued_info1_title" = "Respect Your Privacy"; "lng_sponsored_revenued_info1_description" = "Ads on Telegram do not use your personal information and are abased on the channel in which you see them."; diff --git a/Telegram/SourceFiles/data/data_sponsored_messages.cpp b/Telegram/SourceFiles/data/data_sponsored_messages.cpp index 2289dfbd1..ae37e9191 100644 --- a/Telegram/SourceFiles/data/data_sponsored_messages.cpp +++ b/Telegram/SourceFiles/data/data_sponsored_messages.cpp @@ -482,6 +482,83 @@ void SponsoredMessages::clicked(const FullMsgId &fullId) { )).send(); } + +auto SponsoredMessages::createReportCallback(const FullMsgId &fullId) +-> Fn)> { + using TLChoose = MTPDchannels_sponsoredMessageReportResultChooseOption; + using TLAdsHidden = MTPDchannels_sponsoredMessageReportResultAdsHidden; + using TLReported = MTPDchannels_sponsoredMessageReportResultReported; + using Result = SponsoredReportResult; + + struct State final { +#ifdef _DEBUG + ~State() { + qDebug() << "SponsoredMessages Report ~State()."; + } +#endif + mtpRequestId requestId = 0; + }; + const auto state = std::make_shared(); + + return [=](Result::Id optionId, Fn done) { + const auto entry = find(fullId); + if (!entry) { + return; + } + + const auto history = entry->item->history(); + const auto channel = history->peer->asChannel(); + if (!channel) { + return; + } + + state->requestId = _session->api().request( + MTPchannels_ReportSponsoredMessage( + channel->inputChannel, + MTP_bytes(entry->sponsored.randomId), + MTP_bytes(optionId)) + ).done([=]( + const MTPchannels_SponsoredMessageReportResult &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 TLAdsHidden &data) -> Result { + return { .result = Result::FinalStep::Hidden }; + }, [&](const TLReported &data) -> Result { + const auto it = _data.find(history); + if (it != end(_data)) { + auto &list = it->second.entries; + const auto proj = [&](const Entry &e) { + return e.itemFullId == fullId; + }; + list.erase(ranges::remove_if(list, proj), end(list)); + } + return { .result = Result::FinalStep::Reported }; + })); + }).fail([=](const MTP::Error &error) { + state->requestId = 0; + if (error.type() == u"PREMIUM_ACCOUNT_REQUIRED"_q) { + done({ .result = Result::FinalStep::Premium }); + } else { + done({ .error = error.type() }); + } + }).send(); + }; +} + SponsoredMessages::State SponsoredMessages::state( not_null history) const { const auto it = _data.find(history); diff --git a/Telegram/SourceFiles/data/data_sponsored_messages.h b/Telegram/SourceFiles/data/data_sponsored_messages.h index fe55520fc..04f0cd196 100644 --- a/Telegram/SourceFiles/data/data_sponsored_messages.h +++ b/Telegram/SourceFiles/data/data_sponsored_messages.h @@ -22,6 +22,24 @@ namespace Data { class Session; +struct SponsoredReportResult final { + using Id = QByteArray; + struct Option final { + Id id = 0; + QString text; + }; + using Options = std::vector