Support "recommended" sponsored messages.

This commit is contained in:
John Preston 2022-05-10 19:04:29 +04:00
parent 6dedf7c63e
commit 63940ea557
7 changed files with 14 additions and 3 deletions

View File

@ -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}";

View File

@ -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<PeerData*> 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() },
};
};

View File

@ -30,6 +30,7 @@ struct SponsoredFrom {
bool isPublic = false;
bool isBot = false;
bool isExactPost = false;
bool isRecommended = false;
ImageWithLocation userpic;
};

View File

@ -121,6 +121,7 @@ struct HistoryMessageSponsored : public RuntimeComponent<HistoryMessageSponsored
};
std::unique_ptr<HiddenSenderInfo> sender;
Type type = Type::User;
bool recommended = false;
};
struct HistoryMessageReply : public RuntimeComponent<HistoryMessageReply, HistoryItem> {

View File

@ -1787,6 +1787,7 @@ void HistoryMessage::setSponsoredFrom(const Data::SponsoredFrom &from) {
sponsored->sender = std::make_unique<HiddenSenderInfo>(
from.title,
false);
sponsored->recommended = from.isRecommended;
if (from.userpic.location.valid()) {
sponsored->sender->customUserpic.set(
&history()->session(),

View File

@ -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*> message) {
if (message->context() == Context::Replies) {
result.flags |= Flag::RepliesContext;
}
if (item->isSponsored()) {
if (const auto sponsored = item->Get<HistoryMessageSponsored>()) {
if (sponsored->recommended) {
result.flags |= Flag::Recommended;
}
result.flags |= Flag::Sponsored;
}
if (item->isPinned() && message->context() != Context::Pinned) {

View File

@ -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; };