From 099482574e78599a7ee4559326fdbc41adbf5847 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 16 Jun 2020 20:53:44 +0400 Subject: [PATCH] Fix sending stickers from inline bots. Fixes #8020. --- .../SourceFiles/data/data_media_types.cpp | 40 +++++++++++++------ Telegram/SourceFiles/data/data_media_types.h | 36 +++++++++++------ .../admin_log/history_admin_log_inner.cpp | 10 +++-- .../admin_log/history_admin_log_inner.h | 6 ++- Telegram/SourceFiles/history/history.cpp | 4 +- .../history/history_inner_widget.cpp | 18 ++++++--- Telegram/SourceFiles/history/history_item.h | 3 +- .../SourceFiles/history/history_message.cpp | 5 ++- .../SourceFiles/history/history_message.h | 3 +- .../SourceFiles/history/history_service.cpp | 5 ++- .../SourceFiles/history/history_service.h | 3 +- .../history/view/history_view_element.cpp | 20 ++++++---- .../history/view/history_view_element.h | 17 +++++--- .../history/view/history_view_list_widget.cpp | 10 +++-- .../history/view/history_view_list_widget.h | 6 ++- .../history/view/history_view_message.cpp | 5 ++- .../history/view/history_view_message.h | 3 +- .../view/history_view_service_message.cpp | 5 ++- .../view/history_view_service_message.h | 3 +- .../history/view/media/history_view_dice.h | 2 - .../history/view/media/history_view_media.cpp | 5 +++ .../history/view/media/history_view_media.h | 7 +++- .../media/history_view_media_unwrapped.cpp | 10 +++++ .../view/media/history_view_media_unwrapped.h | 8 ++-- .../view/media/history_view_sticker.cpp | 29 +++++++++++++- .../history/view/media/history_view_sticker.h | 6 ++- .../inline_bot_layout_internal.cpp | 2 +- 27 files changed, 192 insertions(+), 79 deletions(-) diff --git a/Telegram/SourceFiles/data/data_media_types.cpp b/Telegram/SourceFiles/data/data_media_types.cpp index 1b47c63dd..134447224 100644 --- a/Telegram/SourceFiles/data/data_media_types.cpp +++ b/Telegram/SourceFiles/data/data_media_types.cpp @@ -244,8 +244,9 @@ TextWithEntities Media::consumedMessageText() const { } std::unique_ptr Media::createView( - not_null message) { - return createView(message, message->data()); + not_null message, + HistoryView::Element *replacing) { + return createView(message, message->data(), replacing); } MediaPhoto::MediaPhoto( @@ -386,7 +387,8 @@ bool MediaPhoto::updateSentMedia(const MTPMessageMedia &media) { std::unique_ptr MediaPhoto::createView( not_null message, - not_null realParent) { + not_null realParent, + HistoryView::Element *replacing) { if (_chat) { return std::make_unique( message, @@ -663,11 +665,15 @@ bool MediaFile::updateSentMedia(const MTPMessageMedia &media) { std::unique_ptr MediaFile::createView( not_null message, - not_null realParent) { + not_null realParent, + HistoryView::Element *replacing) { if (_document->sticker()) { return std::make_unique( message, - std::make_unique(message, _document)); + std::make_unique( + message, + _document, + replacing)); } else if (_document->isAnimation() || _document->isVideoFile()) { return std::make_unique( message, @@ -760,7 +766,8 @@ bool MediaContact::updateSentMedia(const MTPMessageMedia &media) { std::unique_ptr MediaContact::createView( not_null message, - not_null realParent) { + not_null realParent, + HistoryView::Element *replacing) { return std::make_unique( message, _contact.userId, @@ -840,7 +847,8 @@ bool MediaLocation::updateSentMedia(const MTPMessageMedia &media) { std::unique_ptr MediaLocation::createView( not_null message, - not_null realParent) { + not_null realParent, + HistoryView::Element *replacing) { return std::make_unique( message, _location, @@ -900,7 +908,8 @@ bool MediaCall::updateSentMedia(const MTPMessageMedia &media) { std::unique_ptr MediaCall::createView( not_null message, - not_null realParent) { + not_null realParent, + HistoryView::Element *replacing) { return std::make_unique(message, &_call); } @@ -995,7 +1004,8 @@ bool MediaWebPage::updateSentMedia(const MTPMessageMedia &media) { std::unique_ptr MediaWebPage::createView( not_null message, - not_null realParent) { + not_null realParent, + HistoryView::Element *replacing) { return std::make_unique(message, _page); } @@ -1086,7 +1096,8 @@ bool MediaGame::updateSentMedia(const MTPMessageMedia &media) { std::unique_ptr MediaGame::createView( not_null message, - not_null realParent) { + not_null realParent, + HistoryView::Element *replacing) { return std::make_unique( message, _game, @@ -1151,7 +1162,8 @@ bool MediaInvoice::updateSentMedia(const MTPMessageMedia &media) { std::unique_ptr MediaInvoice::createView( not_null message, - not_null realParent) { + not_null realParent, + HistoryView::Element *replacing) { return std::make_unique(message, &_invoice); } @@ -1217,7 +1229,8 @@ bool MediaPoll::updateSentMedia(const MTPMessageMedia &media) { std::unique_ptr MediaPoll::createView( not_null message, - not_null realParent) { + not_null realParent, + HistoryView::Element *replacing) { return std::make_unique(message, _poll); } @@ -1274,7 +1287,8 @@ bool MediaDice::updateSentMedia(const MTPMessageMedia &media) { std::unique_ptr MediaDice::createView( not_null message, - not_null realParent) { + not_null realParent, + HistoryView::Element *replacing) { return std::make_unique( message, std::make_unique(message, this)); diff --git a/Telegram/SourceFiles/data/data_media_types.h b/Telegram/SourceFiles/data/data_media_types.h index ab09b28f4..dfae6ce8c 100644 --- a/Telegram/SourceFiles/data/data_media_types.h +++ b/Telegram/SourceFiles/data/data_media_types.h @@ -111,9 +111,11 @@ public: virtual bool updateSentMedia(const MTPMessageMedia &media) = 0; virtual std::unique_ptr createView( not_null message, - not_null realParent) = 0; + not_null realParent, + HistoryView::Element *replacing = nullptr) = 0; std::unique_ptr createView( - not_null message); + not_null message, + HistoryView::Element *replacing = nullptr); private: const not_null _parent; @@ -152,7 +154,8 @@ public: bool updateSentMedia(const MTPMessageMedia &media) override; std::unique_ptr createView( not_null message, - not_null realParent) override; + not_null realParent, + HistoryView::Element *replacing = nullptr) override; private: not_null _photo; @@ -189,7 +192,8 @@ public: bool updateSentMedia(const MTPMessageMedia &media) override; std::unique_ptr createView( not_null message, - not_null realParent) override; + not_null realParent, + HistoryView::Element *replacing = nullptr) override; private: not_null _document; @@ -218,7 +222,8 @@ public: bool updateSentMedia(const MTPMessageMedia &media) override; std::unique_ptr createView( not_null message, - not_null realParent) override; + not_null realParent, + HistoryView::Element *replacing = nullptr) override; private: SharedContact _contact; @@ -248,7 +253,8 @@ public: bool updateSentMedia(const MTPMessageMedia &media) override; std::unique_ptr createView( not_null message, - not_null realParent) override; + not_null realParent, + HistoryView::Element *replacing = nullptr) override; private: LocationPoint _point; @@ -276,7 +282,8 @@ public: bool updateSentMedia(const MTPMessageMedia &media) override; std::unique_ptr createView( not_null message, - not_null realParent) override; + not_null realParent, + HistoryView::Element *replacing = nullptr) override; static QString Text( not_null item, @@ -312,7 +319,8 @@ public: bool updateSentMedia(const MTPMessageMedia &media) override; std::unique_ptr createView( not_null message, - not_null realParent) override; + not_null realParent, + HistoryView::Element *replacing = nullptr) override; private: not_null _page; @@ -343,7 +351,8 @@ public: bool updateSentMedia(const MTPMessageMedia &media) override; std::unique_ptr createView( not_null message, - not_null realParent) override; + not_null realParent, + HistoryView::Element *replacing = nullptr) override; private: not_null _game; @@ -374,7 +383,8 @@ public: bool updateSentMedia(const MTPMessageMedia &media) override; std::unique_ptr createView( not_null message, - not_null realParent) override; + not_null realParent, + HistoryView::Element *replacing = nullptr) override; private: Invoice _invoice; @@ -401,7 +411,8 @@ public: bool updateSentMedia(const MTPMessageMedia &media) override; std::unique_ptr createView( not_null message, - not_null realParent) override; + not_null realParent, + HistoryView::Element *replacing = nullptr) override; private: not_null _poll; @@ -425,7 +436,8 @@ public: bool updateSentMedia(const MTPMessageMedia &media) override; std::unique_ptr createView( not_null message, - not_null realParent) override; + not_null realParent, + HistoryView::Element *replacing = nullptr) override; private: QString _emoji; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index a7ce8a355..c71150adb 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -537,13 +537,15 @@ HistoryView::Context InnerWidget::elementContext() { } std::unique_ptr InnerWidget::elementCreate( - not_null message) { - return std::make_unique(this, message); + not_null message, + Element *replacing) { + return std::make_unique(this, message, replacing); } std::unique_ptr InnerWidget::elementCreate( - not_null message) { - return std::make_unique(this, message); + not_null message, + Element *replacing) { + return std::make_unique(this, message, replacing); } bool InnerWidget::elementUnderCursor( diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h index 3d2d228e4..9ed7773b5 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h @@ -89,9 +89,11 @@ public: // HistoryView::ElementDelegate interface. HistoryView::Context elementContext() override; std::unique_ptr elementCreate( - not_null message) override; + not_null message, + HistoryView::Element *replacing = nullptr) override; std::unique_ptr elementCreate( - not_null message) override; + not_null message, + HistoryView::Element *replacing = nullptr) override; bool elementUnderCursor( not_null view) override; void elementAnimationAutoplayAsync( diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 0c1d977a7..96b1f786e 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -3364,7 +3364,9 @@ void HistoryBlock::refreshView(not_null view) { Expects(view->block() == this); const auto item = view->data(); - auto refreshed = item->createView(HistoryInner::ElementDelegate()); + auto refreshed = item->createView( + HistoryInner::ElementDelegate(), + view); auto blockIndex = indexInHistory(); auto itemIndex = view->indexInBlock(); diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index f437c792a..6db197773 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2367,7 +2367,7 @@ HistoryInner::~HistoryInner() { for (const auto &item : _animatedStickersPlayed) { if (const auto view = item->mainView()) { if (const auto media = view->media()) { - media->clearStickerLoopPlayed(); + media->stickerClearLoopPlayed(); } } } @@ -3314,12 +3314,20 @@ not_null HistoryInner::ElementDelegate() { return HistoryView::Context::History; } std::unique_ptr elementCreate( - not_null message) override { - return std::make_unique(this, message); + not_null message, + Element *replacing = nullptr) override { + return std::make_unique( + this, + message, + replacing); } std::unique_ptr elementCreate( - not_null message) override { - return std::make_unique(this, message); + not_null message, + Element *replacing = nullptr) override { + return std::make_unique( + this, + message, + replacing); } bool elementUnderCursor( not_null view) override { diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index 20ec30e1e..1310c283c 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -326,7 +326,8 @@ public: [[nodiscard]] PeerData *displayFrom() const; [[nodiscard]] virtual std::unique_ptr createView( - not_null delegate) = 0; + not_null delegate, + HistoryView::Element *replacing = nullptr) = 0; void updateDate(TimeId newDate); [[nodiscard]] bool canUpdateDate() const; diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 16c6dabde..595f287ed 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -1387,8 +1387,9 @@ QString HistoryMessage::notificationHeader() const { } std::unique_ptr HistoryMessage::createView( - not_null delegate) { - return delegate->elementCreate(this); + not_null delegate, + HistoryView::Element *replacing) { + return delegate->elementCreate(this, replacing); } HistoryMessage::~HistoryMessage() { diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h index 8b783edf9..52718a245 100644 --- a/Telegram/SourceFiles/history/history_message.h +++ b/Telegram/SourceFiles/history/history_message.h @@ -168,7 +168,8 @@ public: } [[nodiscard]] std::unique_ptr createView( - not_null delegate) override; + not_null delegate, + HistoryView::Element *replacing = nullptr) override; ~HistoryMessage(); diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index 4856847d2..2164a9190 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -562,8 +562,9 @@ QString HistoryService::inReplyText() const { } std::unique_ptr HistoryService::createView( - not_null delegate) { - return delegate->elementCreate(this); + not_null delegate, + HistoryView::Element *replacing) { + return delegate->elementCreate(this, replacing); } QString HistoryService::fromLinkText() const { diff --git a/Telegram/SourceFiles/history/history_service.h b/Telegram/SourceFiles/history/history_service.h index fe06d26ad..0b68c1842 100644 --- a/Telegram/SourceFiles/history/history_service.h +++ b/Telegram/SourceFiles/history/history_service.h @@ -105,7 +105,8 @@ public: QString inReplyText() const override; std::unique_ptr createView( - not_null delegate) override; + not_null delegate, + HistoryView::Element *replacing = nullptr) override; ~HistoryService(); diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 50fea5fe7..1c8f26517 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -56,13 +56,15 @@ bool IsAttachedToPreviousInSavedMessages( std::unique_ptr SimpleElementDelegate::elementCreate( - not_null message) { - return std::make_unique(this, message); + not_null message, + Element *replacing) { + return std::make_unique(this, message, replacing); } std::unique_ptr SimpleElementDelegate::elementCreate( - not_null message) { - return std::make_unique(this, message); + not_null message, + Element *replacing) { + return std::make_unique(this, message, replacing); } bool SimpleElementDelegate::elementUnderCursor( @@ -203,14 +205,15 @@ void DateBadge::paint(Painter &p, int y, int w) const { Element::Element( not_null delegate, - not_null data) + not_null data, + Element *replacing) : _delegate(delegate) , _data(data) , _isScheduledUntilOnline(IsItemScheduledUntilOnline(data)) , _dateTime(_isScheduledUntilOnline ? QDateTime() : ItemDateTime(data)) , _context(delegate->elementContext()) { history()->owner().registerItemView(this); - refreshMedia(); + refreshMedia(replacing); if (_context == Context::History) { history()->setHasPendingResizedItems(); } @@ -338,7 +341,7 @@ bool Element::isHidden() const { return isHiddenByGroup(); } -void Element::refreshMedia() { +void Element::refreshMedia(Element *replacing) { _flags &= ~Flag::HiddenByGroup; const auto item = data(); @@ -361,7 +364,7 @@ void Element::refreshMedia() { } const auto session = &history()->session(); if (const auto media = _data->media()) { - _media = media->createView(this); + _media = media->createView(this, replacing); } else if (_data->isIsolatedEmoji() && session->settings().largeEmoji()) { const auto emoji = _data->isolatedEmoji(); @@ -372,6 +375,7 @@ void Element::refreshMedia() { std::make_unique( this, sticker.document, + replacing, sticker.replacements)); } else { _media = std::make_unique( diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index e5a8d3a78..ed841f9cf 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -37,9 +37,11 @@ class ElementDelegate { public: virtual Context elementContext() = 0; virtual std::unique_ptr elementCreate( - not_null message) = 0; + not_null message, + Element *replacing = nullptr) = 0; virtual std::unique_ptr elementCreate( - not_null message) = 0; + not_null message, + Element *replacing = nullptr) = 0; virtual bool elementUnderCursor(not_null view) = 0; virtual void elementAnimationAutoplayAsync( not_null element) = 0; @@ -63,9 +65,11 @@ public: class SimpleElementDelegate : public ElementDelegate { public: std::unique_ptr elementCreate( - not_null message) override; + not_null message, + Element *replacing = nullptr) override; std::unique_ptr elementCreate( - not_null message) override; + not_null message, + Element *replacing = nullptr) override; bool elementUnderCursor(not_null view) override; void elementAnimationAutoplayAsync( not_null element) override; @@ -134,7 +138,8 @@ class Element public: Element( not_null delegate, - not_null data); + not_null data, + Element *replacing); enum class Flag : uchar { NeedsResize = 0x01, @@ -304,7 +309,7 @@ private: virtual QSize performCountOptimalSize() = 0; virtual QSize performCountCurrentSize(int newWidth) = 0; - void refreshMedia(); + void refreshMedia(Element *replacing); const not_null _delegate; const not_null _data; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 2cc353ca8..2aec84380 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -1107,13 +1107,15 @@ Context ListWidget::elementContext() { } std::unique_ptr ListWidget::elementCreate( - not_null message) { - return std::make_unique(this, message); + not_null message, + Element *replacing) { + return std::make_unique(this, message, replacing); } std::unique_ptr ListWidget::elementCreate( - not_null message) { - return std::make_unique(this, message); + not_null message, + Element *replacing) { + return std::make_unique(this, message, replacing); } bool ListWidget::elementUnderCursor( diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index 18e6d4dd5..428352e90 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -184,9 +184,11 @@ public: // ElementDelegate interface. Context elementContext() override; std::unique_ptr elementCreate( - not_null message) override; + not_null message, + Element *replacing = nullptr) override; std::unique_ptr elementCreate( - not_null message) override; + not_null message, + Element *replacing = nullptr) override; bool elementUnderCursor(not_null view) override; void elementAnimationAutoplayAsync( not_null view) override; diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index ab905aa4b..6027b62cd 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -201,8 +201,9 @@ LogEntryOriginal::~LogEntryOriginal() = default; Message::Message( not_null delegate, - not_null data) -: Element(delegate, data) { + not_null data, + Element *replacing) +: Element(delegate, data, replacing) { initLogEntryOriginal(); initPsa(); } diff --git a/Telegram/SourceFiles/history/view/history_view_message.h b/Telegram/SourceFiles/history/view/history_view_message.h index 61effe84c..f8f65a07b 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.h +++ b/Telegram/SourceFiles/history/view/history_view_message.h @@ -41,7 +41,8 @@ class Message : public Element, public base::has_weak_ptr { public: Message( not_null delegate, - not_null data); + not_null data, + Element *replacing); int marginTop() const override; int marginBottom() const override; diff --git a/Telegram/SourceFiles/history/view/history_view_service_message.cpp b/Telegram/SourceFiles/history/view/history_view_service_message.cpp index 3e2328bd3..b8be48278 100644 --- a/Telegram/SourceFiles/history/view/history_view_service_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_service_message.cpp @@ -309,8 +309,9 @@ void serviceColorsUpdated() { Service::Service( not_null delegate, - not_null data) -: Element(delegate, data) { + not_null data, + Element *replacing) +: Element(delegate, data, replacing) { } not_null Service::message() const { diff --git a/Telegram/SourceFiles/history/view/history_view_service_message.h b/Telegram/SourceFiles/history/view/history_view_service_message.h index 41d552772..8b86ca1ad 100644 --- a/Telegram/SourceFiles/history/view/history_view_service_message.h +++ b/Telegram/SourceFiles/history/view/history_view_service_message.h @@ -17,7 +17,8 @@ class Service : public Element { public: Service( not_null delegate, - not_null data); + not_null data, + Element *replacing); int marginTop() const override; int marginBottom() const override; diff --git a/Telegram/SourceFiles/history/view/media/history_view_dice.h b/Telegram/SourceFiles/history/view/media/history_view_dice.h index 8022352ca..f412343b7 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_dice.h +++ b/Telegram/SourceFiles/history/view/media/history_view_dice.h @@ -26,8 +26,6 @@ public: ClickHandlerPtr link() override; - void clearStickerLoopPlayed() override { - } bool hasHeavyPart() const override { return (_start ? _start->hasHeavyPart() : false) || (_end ? _end->hasHeavyPart() : false); diff --git a/Telegram/SourceFiles/history/view/media/history_view_media.cpp b/Telegram/SourceFiles/history/view/media/history_view_media.cpp index b31b1c7a5..6e17e04af 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item.h" #include "history/view/history_view_element.h" #include "history/view/history_view_cursor_state.h" +#include "lottie/lottie_single_player.h" #include "storage/storage_shared_media.h" #include "data/data_document.h" #include "ui/text_options.h" @@ -165,6 +166,10 @@ PointState Media::pointState(QPoint point) const { : PointState::Outside; } +std::unique_ptr Media::stickerTakeLottie() { + return nullptr; +} + TextState Media::getStateGrouped( const QRect &geometry, RectParts sides, diff --git a/Telegram/SourceFiles/history/view/media/history_view_media.h b/Telegram/SourceFiles/history/view/media/history_view_media.h index 52a8155a8..0b16b63be 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media.h +++ b/Telegram/SourceFiles/history/view/media/history_view_media.h @@ -24,6 +24,10 @@ enum class SharedMediaType : signed char; using SharedMediaTypesMask = base::enum_mask; } // namespace Storage +namespace Lottie { +class SinglePlayer; +} // namespace Lottie + namespace HistoryView { enum class PointState : char; @@ -139,8 +143,9 @@ public: } virtual void stopAnimation() { } - virtual void clearStickerLoopPlayed() { + virtual void stickerClearLoopPlayed() { } + virtual std::unique_ptr stickerTakeLottie(); virtual void checkAnimation() { } diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp index 4b974cf5b..db75eed40 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_cursor_state.h" #include "history/history_item.h" #include "history/history_item_components.h" +#include "lottie/lottie_single_player.h" #include "layout.h" #include "facades.h" #include "app.h" @@ -24,6 +25,11 @@ constexpr auto kMaxForwardedBarLines = 4; } // namespace +auto UnwrappedMedia::Content::stickerTakeLottie() +-> std::unique_ptr { + return nullptr; +} + UnwrappedMedia::UnwrappedMedia( not_null parent, std::unique_ptr content) @@ -376,6 +382,10 @@ TextState UnwrappedMedia::textState(QPoint point, StateRequest request) const { return result; } +std::unique_ptr UnwrappedMedia::stickerTakeLottie() { + return _content->stickerTakeLottie(); +} + int UnwrappedMedia::calculateFullRight(const QRect &inner) const { const auto rightAligned = _parent->hasOutLayout() && !Adaptive::ChatWide(); const auto infoWidth = _parent->infoWidth() diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.h b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.h index 5e38073da..ecda739fd 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.h +++ b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.h @@ -32,8 +32,9 @@ public: [[nodiscard]] virtual DocumentData *document() { return nullptr; } - virtual void clearStickerLoopPlayed() { + virtual void stickerClearLoopPlayed() { } + virtual std::unique_ptr stickerTakeLottie(); virtual bool hasHeavyPart() const { return false; } @@ -81,9 +82,10 @@ public: bool hidesForwardedInfo() const override { return _content->hidesForwardedInfo(); } - void clearStickerLoopPlayed() override { - _content->clearStickerLoopPlayed(); + void stickerClearLoopPlayed() override { + _content->stickerClearLoopPlayed(); } + std::unique_ptr stickerTakeLottie() override; bool hasHeavyPart() const override { return _content->hasHeavyPart(); diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp index f80c4c207..1a55b9691 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp @@ -57,11 +57,22 @@ namespace { Sticker::Sticker( not_null parent, not_null data, + Element *replacing, const Lottie::ColorReplacements *replacements) : _parent(parent) , _data(data) , _replacements(replacements) { - _data->loadThumbnail(parent->data()->fullId()); + if ((_dataMedia = _data->activeMediaView())) { + dataMediaCreated(); + } else { + _data->loadThumbnail(parent->data()->fullId()); + } + if (const auto media = replacing ? replacing->media() : nullptr) { + _lottie = media->stickerTakeLottie(); + if (_lottie) { + lottieCreated(); + } + } } Sticker::~Sticker() { @@ -263,6 +274,12 @@ void Sticker::ensureDataMediaCreated() const { return; } _dataMedia = _data->createMediaView(); + dataMediaCreated(); +} + +void Sticker::dataMediaCreated() const { + Expects(_dataMedia != nullptr); + _dataMedia->goodThumbnailWanted(); _dataMedia->thumbnailWanted(_parent->data()->fullId()); _parent->history()->owner().registerHeavyViewPart(_parent); @@ -282,6 +299,12 @@ void Sticker::setupLottie() { Stickers::LottieSize::MessageHistory, _size * cIntRetinaFactor(), Lottie::Quality::High); + lottieCreated(); +} + +void Sticker::lottieCreated() { + Expects(_lottie != nullptr); + _parent->history()->owner().registerHeavyViewPart(_parent); _lottie->updates( @@ -315,4 +338,8 @@ void Sticker::unloadLottie() { _parent->checkHeavyPart(); } +std::unique_ptr< Lottie::SinglePlayer> Sticker::stickerTakeLottie() { + return std::move(_lottie); +} + } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.h b/Telegram/SourceFiles/history/view/media/history_view_sticker.h index 7c874d6ee..468748267 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, + Element *replacing = nullptr, const Lottie::ColorReplacements *replacements = nullptr); ~Sticker(); @@ -46,9 +47,10 @@ public: DocumentData *document() override { return _data; } - void clearStickerLoopPlayed() override { + void stickerClearLoopPlayed() override { _lottieOncePlayed = false; } + std::unique_ptr stickerTakeLottie() override; bool hasHeavyPart() const override; void unloadHeavyPart() override; @@ -74,8 +76,10 @@ private: [[nodiscard]] QPixmap paintedPixmap(bool selected) const; void ensureDataMediaCreated() const; + void dataMediaCreated() const; void setupLottie(); + void lottieCreated(); void unloadLottie(); const not_null _parent; diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp index d5a9b930a..7bd6f7c6f 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp @@ -550,7 +550,7 @@ void Sticker::prepareThumbnail() const { } _dataMedia->checkStickerSmall(); if (const auto sticker = _dataMedia->getStickerSmall()) { - if (!_lottie && !_thumbLoaded && _dataMedia->loaded()) { + if (!_lottie && !_thumbLoaded) { const auto thumbSize = getThumbSize(); _thumb = sticker->pix( thumbSize.width(),