From 63940ea55759b6b563f8f4cc2611bc54baeb45ac Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 10 May 2022 19:04:29 +0400 Subject: [PATCH] Support "recommended" sponsored messages. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/data/data_sponsored_messages.cpp | 3 ++- Telegram/SourceFiles/data/data_sponsored_messages.h | 1 + Telegram/SourceFiles/history/history_item_components.h | 1 + Telegram/SourceFiles/history/history_message.cpp | 1 + .../history/view/history_view_bottom_info.cpp | 9 +++++++-- .../SourceFiles/history/view/history_view_bottom_info.h | 1 + 7 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index b57e4409ee..5d224185be 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1576,6 +1576,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_signed_author" = "Author: {user}"; "lng_in_reply_to" = "In reply to"; "lng_sponsored" = "sponsored"; +"lng_recommended" = "recommended"; "lng_edited" = "edited"; "lng_edited_date" = "Edited: {date}"; "lng_sent_date" = "Sent: {date}"; diff --git a/Telegram/SourceFiles/data/data_sponsored_messages.cpp b/Telegram/SourceFiles/data/data_sponsored_messages.cpp index 8399febad4..9b490701f2 100644 --- a/Telegram/SourceFiles/data/data_sponsored_messages.cpp +++ b/Telegram/SourceFiles/data/data_sponsored_messages.cpp @@ -152,7 +152,7 @@ void SponsoredMessages::append( }); const auto randomId = data.vrandom_id().v; const auto hash = qs(data.vchat_invite_hash().value_or_empty()); - const auto makeFrom = []( + const auto makeFrom = [&]( not_null peer, bool exactPost = false) { const auto channel = peer->asChannel(); @@ -165,6 +165,7 @@ void SponsoredMessages::append( .isPublic = (channel && channel->isPublic()), .isBot = (peer->isUser() && peer->asUser()->isBot()), .isExactPost = exactPost, + .isRecommended = data.is_recommended(), .userpic = { .location = peer->userpicLocation() }, }; }; diff --git a/Telegram/SourceFiles/data/data_sponsored_messages.h b/Telegram/SourceFiles/data/data_sponsored_messages.h index 6159e40864..be791a1c08 100644 --- a/Telegram/SourceFiles/data/data_sponsored_messages.h +++ b/Telegram/SourceFiles/data/data_sponsored_messages.h @@ -30,6 +30,7 @@ struct SponsoredFrom { bool isPublic = false; bool isBot = false; bool isExactPost = false; + bool isRecommended = false; ImageWithLocation userpic; }; diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index d594a7f6bd..3b642dbe24 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -121,6 +121,7 @@ struct HistoryMessageSponsored : public RuntimeComponent sender; Type type = Type::User; + bool recommended = false; }; struct HistoryMessageReply : public RuntimeComponent { diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 72657b2f38..673cea44e1 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -1787,6 +1787,7 @@ void HistoryMessage::setSponsoredFrom(const Data::SponsoredFrom &from) { sponsored->sender = std::make_unique( from.title, false); + sponsored->recommended = from.isRecommended; if (from.userpic.location.valid()) { sponsored->sender->customUserpic.set( &history()->session(), diff --git a/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp b/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp index 43cddbd771..d8a54d68b1 100644 --- a/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp +++ b/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp @@ -426,7 +426,9 @@ void BottomInfo::layoutDateText() { const auto name = _authorElided ? st::msgDateFont->elided(author, maxWidth - afterAuthorWidth) : author; - const auto full = (_data.flags & Data::Flag::Sponsored) + const auto full = (_data.flags & Data::Flag::Recommended) + ? tr::lng_recommended(tr::now) + : (_data.flags & Data::Flag::Sponsored) ? tr::lng_sponsored(tr::now) : (_data.flags & Data::Flag::Imported) ? (date + ' ' + tr::lng_imported(tr::now)) @@ -586,7 +588,10 @@ BottomInfo::Data BottomInfoDataFromMessage(not_null message) { if (message->context() == Context::Replies) { result.flags |= Flag::RepliesContext; } - if (item->isSponsored()) { + if (const auto sponsored = item->Get()) { + if (sponsored->recommended) { + result.flags |= Flag::Recommended; + } result.flags |= Flag::Sponsored; } if (item->isPinned() && message->context() != Context::Pinned) { diff --git a/Telegram/SourceFiles/history/view/history_view_bottom_info.h b/Telegram/SourceFiles/history/view/history_view_bottom_info.h index b9c370dfff..ab88def681 100644 --- a/Telegram/SourceFiles/history/view/history_view_bottom_info.h +++ b/Telegram/SourceFiles/history/view/history_view_bottom_info.h @@ -41,6 +41,7 @@ public: Sponsored = 0x10, Pinned = 0x20, Imported = 0x40, + Recommended = 0x80, //Unread, // We don't want to pass and update it in Date for now. }; friend inline constexpr bool is_flag_type(Flag) { return true; };