diff --git a/Telegram/SourceFiles/history/view/media/history_view_dice.h b/Telegram/SourceFiles/history/view/media/history_view_dice.h index 2e784ed1a..a256fb26c 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_dice.h +++ b/Telegram/SourceFiles/history/view/media/history_view_dice.h @@ -28,6 +28,8 @@ public: void clearStickerLoopPlayed() override { } + void checkHeavyPart() override { + } void unloadHeavyPart() override { if (_start) { _start->unloadHeavyPart(); diff --git a/Telegram/SourceFiles/history/view/media/history_view_game.h b/Telegram/SourceFiles/history/view/media/history_view_game.h index b9707091a..be21390f1 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_game.h +++ b/Telegram/SourceFiles/history/view/media/history_view_game.h @@ -78,14 +78,19 @@ public: return _attach.get(); } + void parentTextUpdated() override; + + void checkHeavyPart() override { + if (_attach) { + _attach->checkHeavyPart(); + } + } void unloadHeavyPart() override { if (_attach) { _attach->unloadHeavyPart(); } } - void parentTextUpdated() override; - ~Game(); private: diff --git a/Telegram/SourceFiles/history/view/media/history_view_invoice.h b/Telegram/SourceFiles/history/view/media/history_view_invoice.h index 5fbc1ffc2..9a0b5d665 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_invoice.h +++ b/Telegram/SourceFiles/history/view/media/history_view_invoice.h @@ -66,16 +66,21 @@ public: return false; } + Media *attach() const { + return _attach.get(); + } + + void checkHeavyPart() override { + if (_attach) { + _attach->checkHeavyPart(); + } + } void unloadHeavyPart() override { if (_attach) { _attach->unloadHeavyPart(); } } - Media *attach() const { - return _attach.get(); - } - private: QSize countOptimalSize() override; QSize countCurrentSize(int newWidth) override; diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp index 044d75305..72bbbcf1c 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp @@ -66,6 +66,8 @@ Sticker::Sticker( Sticker::~Sticker() { unloadLottie(); + _dataMedia = nullptr; + checkHeavyPart(); } bool Sticker::isEmojiSticker() const { @@ -244,7 +246,7 @@ void Sticker::refreshLink() { return; } that->_lottieOncePlayed = false; - that->_parent->data()->history()->owner().requestViewRepaint( + that->_parent->history()->owner().requestViewRepaint( that->_parent); }); } else if (sticker && sticker->set.type() != mtpc_inputStickerSetEmpty) { @@ -260,6 +262,7 @@ void Sticker::ensureDataMediaCreated() const { } _dataMedia = _data->createMediaView(); _dataMedia->goodThumbnailWanted(); + _parent->history()->owner().registerHeavyViewPart(_parent); } void Sticker::setDiceIndex(const QString &emoji, int index) { @@ -274,18 +277,29 @@ void Sticker::setupLottie() { Stickers::LottieSize::MessageHistory, _size * cIntRetinaFactor(), Lottie::Quality::High); - _parent->data()->history()->owner().registerHeavyViewPart(_parent); + _parent->history()->owner().registerHeavyViewPart(_parent); _lottie->updates( ) | rpl::start_with_next([=](Lottie::Update update) { update.data.match([&](const Lottie::Information &information) { - _parent->data()->history()->owner().requestViewResize(_parent); + _parent->history()->owner().requestViewResize(_parent); }, [&](const Lottie::DisplayFrameRequest &request) { - _parent->data()->history()->owner().requestViewRepaint(_parent); + _parent->history()->owner().requestViewRepaint(_parent); }); }, _lifetime); } +void Sticker::checkHeavyPart() { + if (!_dataMedia && !_lottie) { + _parent->history()->owner().unregisterHeavyViewPart(_parent); + } +} + +void Sticker::unloadHeavyPart() { + unloadLottie(); + _dataMedia = nullptr; +} + void Sticker::unloadLottie() { if (!_lottie) { return; @@ -295,7 +309,7 @@ void Sticker::unloadLottie() { _lottieOncePlayed = false; } _lottie = nullptr; - _parent->data()->history()->owner().unregisterHeavyViewPart(_parent); + checkHeavyPart(); } } // 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 b68a0e598..1ae3217e9 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.h +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.h @@ -49,9 +49,10 @@ public: void clearStickerLoopPlayed() override { _lottieOncePlayed = false; } - void unloadHeavyPart() override { - unloadLottie(); - } + + void checkHeavyPart() override; + void unloadHeavyPart() override; + void refreshLink() override; void setDiceIndex(const QString &emoji, int index); diff --git a/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp index acc030e4f..3d1eb8439 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp @@ -8,10 +8,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/media/history_view_theme_document.h" #include "layout.h" +#include "history/history.h" #include "history/history_item.h" #include "history/view/history_view_element.h" #include "history/view/history_view_cursor_state.h" #include "data/data_document.h" +#include "data/data_session.h" #include "data/data_document_media.h" #include "data/data_file_origin.h" #include "base/qthelp_url.h" @@ -38,6 +40,11 @@ ThemeDocument::ThemeDocument( setStatusSize(FileStatusSizeReady, _data->size, -1, 0); } +ThemeDocument::~ThemeDocument() { + _dataMedia = nullptr; + checkHeavyPart(); +} + void ThemeDocument::fillPatternFieldsFrom(const QString &url) { const auto paramsPosition = url.indexOf('?'); if (paramsPosition < 0) { @@ -185,6 +192,7 @@ void ThemeDocument::validateThumbnail() const { if (!_dataMedia) { _dataMedia = _data->createMediaView(); _dataMedia->goodThumbnailWanted(); + _parent->history()->owner().registerHeavyViewPart(_parent); } if (const auto good = _dataMedia->goodThumbnail()) { if (good->loaded()) { @@ -288,4 +296,14 @@ QString ThemeDocument::additionalInfoString() const { return result; } +void ThemeDocument::checkHeavyPart() { + if (!_dataMedia) { + _parent->history()->owner().unregisterHeavyViewPart(_parent); + } +} + +void ThemeDocument::unloadHeavyPart() { + _dataMedia = nullptr; +} + } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/media/history_view_theme_document.h b/Telegram/SourceFiles/history/view/media/history_view_theme_document.h index 586aad2db..b7bf40090 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_theme_document.h +++ b/Telegram/SourceFiles/history/view/media/history_view_theme_document.h @@ -21,6 +21,7 @@ public: not_null parent, not_null document, const QString &url = QString()); + ~ThemeDocument(); void draw( Painter &p, @@ -45,6 +46,9 @@ public: bool isReadyForOpen() const override; QString additionalInfoString() const override; + void checkHeavyPart() override; + void unloadHeavyPart() override; + protected: float64 dataProgress() const override; bool dataFinished() const override; diff --git a/Telegram/SourceFiles/history/view/media/history_view_web_page.h b/Telegram/SourceFiles/history/view/media/history_view_web_page.h index b6a3c68b7..95afb0cbb 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_web_page.h +++ b/Telegram/SourceFiles/history/view/media/history_view_web_page.h @@ -81,16 +81,21 @@ public: } bool enforceBubbleWidth() const override; + Media *attach() const { + return _attach.get(); + } + + void checkHeavyPart() override { + if (_attach) { + _attach->checkHeavyPart(); + } + } void unloadHeavyPart() override { if (_attach) { _attach->unloadHeavyPart(); } } - Media *attach() const { - return _attach.get(); - } - ~WebPage(); private: