From 46f9bdd701f2d3976cbc784eafc78d619ebeff0a Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 2 Jun 2022 18:23:33 +0400 Subject: [PATCH] Skip premium effect for nopremium stickers. --- Telegram/Resources/tl/api.tl | 4 +-- .../SourceFiles/data/data_media_types.cpp | 12 ++++++--- Telegram/SourceFiles/data/data_media_types.h | 4 ++- .../SourceFiles/history/history_message.cpp | 9 +++++-- .../history/view/history_view_element.cpp | 2 ++ .../history/view/media/history_view_dice.cpp | 9 ++++--- .../view/media/history_view_media_common.cpp | 6 ++++- .../view/media/history_view_slot_machine.cpp | 3 ++- .../view/media/history_view_sticker.cpp | 25 +++++++++++-------- .../history/view/media/history_view_sticker.h | 3 +++ .../view/media/history_view_web_page.cpp | 4 ++- 11 files changed, 57 insertions(+), 24 deletions(-) diff --git a/Telegram/Resources/tl/api.tl b/Telegram/Resources/tl/api.tl index 46a7c0086..11d38d97f 100644 --- a/Telegram/Resources/tl/api.tl +++ b/Telegram/Resources/tl/api.tl @@ -150,7 +150,7 @@ messageMediaPhoto#695150d7 flags:# photo:flags.0?Photo ttl_seconds:flags.2?int = messageMediaGeo#56e0d474 geo:GeoPoint = MessageMedia; messageMediaContact#70322949 phone_number:string first_name:string last_name:string vcard:string user_id:long = MessageMedia; messageMediaUnsupported#9f84f49e = MessageMedia; -messageMediaDocument#9cb070d7 flags:# document:flags.0?Document ttl_seconds:flags.2?int = MessageMedia; +messageMediaDocument#9cb070d7 flags:# nopremium:flags.3?true document:flags.0?Document ttl_seconds:flags.2?int = MessageMedia; messageMediaWebPage#a32dd600 webpage:WebPage = MessageMedia; messageMediaVenue#2ec0533f geo:GeoPoint title:string address:string provider:string venue_id:string venue_type:string = MessageMedia; messageMediaGame#fdb19008 game:Game = MessageMedia; @@ -1386,7 +1386,7 @@ payments.exportedInvoice#aed0cbd9 url:string = payments.ExportedInvoice; messages.transcribedAudio#93752c52 flags:# pending:flags.0?true transcription_id:long text:string = messages.TranscribedAudio; -help.premiumPromo#3f7ae6ee status_text:string status_entities:Vector video_sections:Vector videos:Vector = help.PremiumPromo; +help.premiumPromo#e0360f1b status_text:string status_entities:Vector video_sections:Vector videos:Vector currency:string monthly_amount:long = help.PremiumPromo; ---functions--- diff --git a/Telegram/SourceFiles/data/data_media_types.cpp b/Telegram/SourceFiles/data/data_media_types.cpp index a60b75128..10503a2f5 100644 --- a/Telegram/SourceFiles/data/data_media_types.cpp +++ b/Telegram/SourceFiles/data/data_media_types.cpp @@ -635,10 +635,12 @@ std::unique_ptr MediaPhoto::createView( MediaFile::MediaFile( not_null parent, - not_null document) + not_null document, + bool skipPremiumEffect) : Media(parent) , _document(document) -, _emoji(document->sticker() ? document->sticker()->alt : QString()) { +, _emoji(document->sticker() ? document->sticker()->alt : QString()) +, _skipPremiumEffect(skipPremiumEffect) { parent->history()->owner().registerDocumentItem(_document, parent); if (!_emoji.isEmpty()) { @@ -658,7 +660,10 @@ MediaFile::~MediaFile() { } std::unique_ptr MediaFile::clone(not_null parent) { - return std::make_unique(parent, _document); + return std::make_unique( + parent, + _document, + !_document->session().premium()); } DocumentData *MediaFile::document() const { @@ -953,6 +958,7 @@ std::unique_ptr MediaFile::createView( std::make_unique( message, _document, + _skipPremiumEffect, replacing)); } else if (_document->isAnimation() || _document->isVideoFile() diff --git a/Telegram/SourceFiles/data/data_media_types.h b/Telegram/SourceFiles/data/data_media_types.h index 34110473f..7c4c83b7a 100644 --- a/Telegram/SourceFiles/data/data_media_types.h +++ b/Telegram/SourceFiles/data/data_media_types.h @@ -185,7 +185,8 @@ class MediaFile final : public Media { public: MediaFile( not_null parent, - not_null document); + not_null document, + bool skipPremiumEffect); ~MediaFile(); std::unique_ptr clone(not_null parent) override; @@ -218,6 +219,7 @@ public: private: not_null _document; QString _emoji; + bool _skipPremiumEffect = false; }; diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 1480722dc..490696d3e 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -534,7 +534,11 @@ HistoryMessage::HistoryMessage( postAuthor, std::move(markup)); - _media = std::make_unique(this, document); + const auto skipPremiumEffect = !history->session().premium(); + _media = std::make_unique( + this, + document, + skipPremiumEffect); setText(caption); } @@ -1173,7 +1177,8 @@ std::unique_ptr HistoryMessage::CreateMedia( return document->match([&](const MTPDdocument &document) -> Result { return std::make_unique( item, - item->history()->owner().processDocument(document)); + item->history()->owner().processDocument(document), + media.is_nopremium()); }, [](const MTPDdocumentEmpty &) -> Result { return nullptr; }); diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index e409f1407..40f7575c0 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -565,12 +565,14 @@ void Element::refreshMedia(Element *replacing) { && Core::App().settings().largeEmoji()) { const auto emoji = _data->isolatedEmoji(); const auto emojiStickers = &session->emojiStickersPack(); + const auto skipPremiumEffect = false; if (const auto sticker = emojiStickers->stickerForEmoji(emoji)) { _media = std::make_unique( this, std::make_unique( this, sticker.document, + skipPremiumEffect, replacing, sticker.replacements)); } else { diff --git a/Telegram/SourceFiles/history/view/media/history_view_dice.cpp b/Telegram/SourceFiles/history/view/media/history_view_dice.cpp index 08b5d3afb..755088a42 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_dice.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_dice.cpp @@ -34,7 +34,8 @@ Dice::Dice(not_null parent, not_null dice) , _dice(dice) , _link(dice->makeHandler()) { if (const auto document = Lookup(parent, dice->emoji(), 0)) { - _start.emplace(parent, document); + const auto skipPremiumEffect = false; + _start.emplace(parent, document, skipPremiumEffect); _start->setDiceIndex(_dice->emoji(), 0); } _showLastFrame = _parent->data()->Has(); @@ -56,14 +57,16 @@ ClickHandlerPtr Dice::link() { void Dice::draw(Painter &p, const PaintContext &context, const QRect &r) { if (!_start) { if (const auto document = Lookup(_parent, _dice->emoji(), 0)) { - _start.emplace(_parent, document); + const auto skipPremiumEffect = false; + _start.emplace(_parent, document, skipPremiumEffect); _start->setDiceIndex(_dice->emoji(), 0); _start->initSize(); } } if (const auto value = _end ? 0 : _dice->value()) { if (const auto document = Lookup(_parent, _dice->emoji(), value)) { - _end.emplace(_parent, document); + const auto skipPremiumEffect = false; + _end.emplace(_parent, document, skipPremiumEffect); _end->setDiceIndex(_dice->emoji(), value); _end->initSize(); } diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_common.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_common.cpp index f091a6ba2..d39ada919 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_common.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_common.cpp @@ -78,9 +78,13 @@ std::unique_ptr CreateAttach( return std::make_unique(parent, collage); } else if (document) { if (document->sticker()) { + const auto skipPremiumEffect = false; return std::make_unique( parent, - std::make_unique(parent, document)); + std::make_unique( + parent, + document, + skipPremiumEffect)); } else if (document->isAnimation() || document->isVideoFile()) { return std::make_unique(parent, parent->data(), document); } else if (document->isWallPaper() || document->isTheme()) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_slot_machine.cpp b/Telegram/SourceFiles/history/view/media/history_view_slot_machine.cpp index c6b26a1b7..1ccadc4d2 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_slot_machine.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_slot_machine.cpp @@ -99,7 +99,8 @@ void SlotMachine::resolve( if (!document) { return; } - sticker.emplace(_parent, document); + const auto skipPremiumEffect = false; + sticker.emplace(_parent, document, skipPremiumEffect); sticker->setDiceIndex(kEmoji, singleTimeIndex); if (initSize) { sticker->initSize(); diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp index b877bb300..ffda3bd81 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp @@ -61,16 +61,18 @@ constexpr auto kEmojiMultiplier = 3; Sticker::Sticker( not_null parent, not_null data, + bool skipPremiumEffect, Element *replacing, const Lottie::ColorReplacements *replacements) : _parent(parent) , _data(data) -, _replacements(replacements) { +, _replacements(replacements) +, _skipPremiumEffect(skipPremiumEffect) { if ((_dataMedia = _data->activeMediaView())) { dataMediaCreated(); } else { _data->loadThumbnail(parent->data()->fullId()); - if (_data->isPremiumSticker()) { + if (hasPremiumEffect()) { _data->loadVideoThumbnail(parent->data()->fullId()); } } @@ -78,8 +80,7 @@ Sticker::Sticker( _lottie = media->stickerTakeLottie(_data, _replacements); if (_lottie) { //_externalInfo = media->externalLottieInfo(); - if (_data->isPremiumSticker() - && !_premiumEffectPlayed) { + if (hasPremiumEffect() && !_premiumEffectPlayed) { _premiumEffectPlayed = true; _parent->delegate()->elementStartPremium(_parent, replacing); } @@ -100,6 +101,10 @@ Sticker::~Sticker() { } } +bool Sticker::hasPremiumEffect() const { + return !_skipPremiumEffect && _data->isPremiumSticker(); +} + bool Sticker::isEmojiSticker() const { return (_parent->data()->media() == nullptr); } @@ -134,7 +139,7 @@ bool Sticker::readyToDrawLottie() { ensureDataMediaCreated(); _dataMedia->checkStickerLarge(); const auto loaded = _dataMedia->loaded(); - const auto waitingForPremium = _data->isPremiumSticker() + const auto waitingForPremium = hasPremiumEffect() && _dataMedia->videoThumbnailContent().isEmpty(); if (sticker->isLottie() && !_lottie && loaded && !waitingForPremium) { setupLottie(); @@ -338,7 +343,7 @@ QPixmap Sticker::paintedPixmap(const PaintContext &context) const { } bool Sticker::mirrorHorizontal() const { - if (!_data->isPremiumSticker()) { + if (!hasPremiumEffect()) { return false; } const auto rightAligned = _parent->hasOutLayout() @@ -368,7 +373,7 @@ void Sticker::refreshLink() { } }); } else if (sticker && sticker->set) { - if (_data->isPremiumSticker()) { + if (hasPremiumEffect()) { const auto weak = base::make_weak(this); _link = std::make_shared([weak] { if (const auto that = weak.get()) { @@ -423,7 +428,7 @@ void Sticker::dataMediaCreated() const { if (_dataMedia->thumbnailPath().isEmpty()) { _dataMedia->thumbnailWanted(_parent->data()->fullId()); } - if (_data->isPremiumSticker()) { + if (hasPremiumEffect()) { _data->loadVideoThumbnail(_parent->data()->fullId()); } _parent->history()->owner().registerHeavyViewPart(_parent); @@ -448,7 +453,7 @@ void Sticker::setupLottie() { } void Sticker::checkPremiumEffectStart() { - if (!_premiumEffectPlayed && _data->isPremiumSticker()) { + if (!_premiumEffectPlayed && hasPremiumEffect()) { _premiumEffectPlayed = true; _parent->delegate()->elementStartPremium(_parent, nullptr); } @@ -488,7 +493,7 @@ void Sticker::unloadLottie() { _lottieOncePlayed = false; } _lottie = nullptr; - if (_data->isPremiumSticker()) { + if (hasPremiumEffect()) { _parent->delegate()->elementCancelPremium(_parent); } _parent->checkHeavyPart(); diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.h b/Telegram/SourceFiles/history/view/media/history_view_sticker.h index b6e269508..127e3873d 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.h +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.h @@ -33,6 +33,7 @@ public: Sticker( not_null parent, not_null data, + bool skipPremiumEffect, Element *replacing = nullptr, const Lottie::ColorReplacements *replacements = nullptr); ~Sticker(); @@ -87,6 +88,7 @@ public: not_null document); private: + [[nodiscard]] bool hasPremiumEffect() const; [[nodiscard]] bool isEmojiSticker() const; void paintLottie(Painter &p, const PaintContext &context, const QRect &r); bool paintPixmap(Painter &p, const PaintContext &context, const QRect &r); @@ -121,6 +123,7 @@ private: mutable bool _lottieOncePlayed = false; mutable bool _premiumEffectPlayed = false; mutable bool _nextLastDiceFrame = false; + bool _skipPremiumEffect = false; rpl::lifetime _lifetime; diff --git a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp index 59ca89201..1cb344cd3 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp @@ -60,9 +60,11 @@ std::vector> PrepareCollageMedia( result.reserve(data.items.size()); for (const auto &item : data.items) { if (const auto document = std::get_if(&item)) { + const auto skipPremiumEffect = false; result.push_back(std::make_unique( parent, - *document)); + *document, + skipPremiumEffect)); } else if (const auto photo = std::get_if(&item)) { result.push_back(std::make_unique( parent,