From d64014c995f7d4d15dabff4f2b1ce49005464a7b Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 21 May 2020 15:40:10 +0400 Subject: [PATCH] Clear DocumentMedia in ReplyPreview. --- Telegram/SourceFiles/data/data_document.cpp | 12 +++++++----- Telegram/SourceFiles/data/data_reply_preview.cpp | 13 +++++++++++-- Telegram/SourceFiles/data/data_reply_preview.h | 1 + .../inline_bots/inline_bot_layout_internal.cpp | 4 +++- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index 71c1a422f6..dd073dda90 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -627,11 +627,13 @@ void DocumentData::updateThumbnails( loadThumbnail(origin); } if (!thumbnail.bytes.isEmpty()) { - owner().cache().putIfEmpty( - _thumbnailLocation.file().cacheKey(), - Storage::Cache::Database::TaggedValue( - base::duplicate(thumbnail.bytes), - Data::kImageCacheTag)); + if (const auto cacheKey = _thumbnailLocation.file().cacheKey()) { + owner().cache().putIfEmpty( + cacheKey, + Storage::Cache::Database::TaggedValue( + base::duplicate(thumbnail.bytes), + Data::kImageCacheTag)); + } } } } diff --git a/Telegram/SourceFiles/data/data_reply_preview.cpp b/Telegram/SourceFiles/data/data_reply_preview.cpp index 001cbc0606..a46e10beae 100644 --- a/Telegram/SourceFiles/data/data_reply_preview.cpp +++ b/Telegram/SourceFiles/data/data_reply_preview.cpp @@ -17,8 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Data { ReplyPreview::ReplyPreview(not_null document) -: _document(document) -, _documentMedia(_document->createMediaView()) { +: _document(document) { } ReplyPreview::ReplyPreview(not_null photo) @@ -59,7 +58,13 @@ void ReplyPreview::prepare(not_null image, Images::Options options) { } Image *ReplyPreview::image(Data::FileOrigin origin) { + if (_checked) { + return _image.get(); + } if (_document) { + if (!_documentMedia) { + _documentMedia = _document->createMediaView(); + } const auto thumbnail = _documentMedia->thumbnail(); if (!_image || (!_good && thumbnail)) { const auto option = _document->isVideoMessage() @@ -73,6 +78,10 @@ Image *ReplyPreview::image(Data::FileOrigin origin) { prepare(image, option | Images::Option::Blurred); } } + if (thumbnail || !_document->hasThumbnail()) { + _checked = true; + _documentMedia = nullptr; + } } } else { Assert(_photo != nullptr); diff --git a/Telegram/SourceFiles/data/data_reply_preview.h b/Telegram/SourceFiles/data/data_reply_preview.h index a1df484492..b607c584d4 100644 --- a/Telegram/SourceFiles/data/data_reply_preview.h +++ b/Telegram/SourceFiles/data/data_reply_preview.h @@ -27,6 +27,7 @@ private: std::unique_ptr _image; bool _good = false; + bool _checked = false; DocumentData *_document = nullptr; PhotoData *_photo = nullptr; std::shared_ptr _documentMedia; diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp index ca6a9a333a..634921e266 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp @@ -133,10 +133,12 @@ int Gif::resizeGetHeight(int width) { void Gif::paint(Painter &p, const QRect &clip, const PaintContext *context) const { const auto document = getShownDocument(); + const auto displayLoading = document->displayLoading(); + ensureDataMediaCreated(document); _dataMedia->automaticLoad(fileOrigin(), nullptr); - bool loaded = _dataMedia->loaded(), loading = document->loading(), displayLoading = document->displayLoading(); + bool loaded = _dataMedia->loaded(), loading = document->loading(); if (loaded && !_gif && !_gif.isBad()