diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 265e1ae33..5f80b3aa6 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -67,15 +67,23 @@ struct StickerIcon { : setId(setId) , thumbnail(thumbnail) , sticker(sticker) - , stickerMedia(sticker ? sticker->createMediaView() : nullptr) , pixw(pixw) , pixh(pixh) { } + + void ensureMediaCreated() const { + if (stickerMedia || !sticker) { + return; + } + stickerMedia = sticker->createMediaView(); + stickerMedia->thumbnailWanted(sticker->stickerSetOrigin()); + } + uint64 setId = 0; ImagePtr thumbnail; mutable Lottie::SinglePlayer *lottie = nullptr; DocumentData *sticker = nullptr; - std::shared_ptr stickerMedia; + mutable std::shared_ptr stickerMedia; ChannelData *megagroup = nullptr; int pixw = 0; int pixh = 0; @@ -700,6 +708,7 @@ void StickersListWidget::Footer::paintSearchIcon(Painter &p) const { void StickersListWidget::Footer::validateIconLottieAnimation( const StickerIcon &icon) { + icon.ensureMediaCreated(); if (icon.lottie || !Stickers::HasLottieThumbnail( icon.thumbnail, @@ -745,6 +754,7 @@ void StickersListWidget::Footer::paintSetIcon( const StickerIcon &icon, int x) const { if (icon.sticker) { + icon.ensureMediaCreated(); const auto origin = icon.sticker->stickerSetOrigin(); const auto thumb = icon.thumbnail ? icon.thumbnail.get() diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index 323fd8cce..35b13096e 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -617,10 +617,17 @@ void DocumentData::updateThumbnails( || _thumbnailLocation.height() < thumbnail.location.height())) { _thumbnailLocation = thumbnail.location; _thumbnailByteSize = thumbnail.bytesCount; - if (_thumbnailLoader) { + if (!thumbnail.preloaded.isNull()) { + _thumbnailLoader = nullptr; + if (const auto media = activeMediaView()) { + media->setThumbnail(thumbnail.preloaded); + } + } else if (_thumbnailLoader) { const auto origin = base::take(_thumbnailLoader)->fileOrigin(); loadThumbnail(origin); - // #TODO optimize replace thumbnail in activeMediaView(). + } + if (!thumbnail.bytes.isEmpty()) { + // #TODO optimize put to cache } } } diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp index 6d0f5f12f..6fbd3c0d5 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp @@ -185,8 +185,8 @@ ClickHandlerPtr ItemBase::getResultPreviewHandler() const { return std::make_shared( _result->_content_url, false); - } else if (_result->_document - && _result->_document->createMediaView()->canBePlayed()) { // #TODO optimize + } else if (const auto document = _result->_document + && _result->_document->createMediaView()->canBePlayed()) { return std::make_shared( _result->_document); } else if (_result->_photo) { diff --git a/Telegram/SourceFiles/storage/file_download_web.cpp b/Telegram/SourceFiles/storage/file_download_web.cpp index 097912ad0..9e0c95dc2 100644 --- a/Telegram/SourceFiles/storage/file_download_web.cpp +++ b/Telegram/SourceFiles/storage/file_download_web.cpp @@ -495,9 +495,7 @@ void webFileLoader::loadProgress(qint64 ready, qint64 total) { void webFileLoader::loadFinished(const QByteArray &data) { cancelRequest(); if (writeResultPart(0, bytes::make_span(data))) { - if (finalizeResult()) { - notifyAboutProgress(); - } + finalizeResult(); } } diff --git a/Telegram/SourceFiles/storage/streamed_file_downloader.cpp b/Telegram/SourceFiles/storage/streamed_file_downloader.cpp index 3cd0a6eb1..bf576c84e 100644 --- a/Telegram/SourceFiles/storage/streamed_file_downloader.cpp +++ b/Telegram/SourceFiles/storage/streamed_file_downloader.cpp @@ -153,14 +153,13 @@ void StreamedFileDownloader::savePart(const LoadedPart &part) { if (!writeResultPart(offset, bytes::make_span(part.bytes))) { return; } - if (_partsSaved == _partsCount) { - if (!finalizeResult()) { - return; - } - } _reader->doneForDownloader(offset); - requestParts(); - notifyAboutProgress(); + if (_partsSaved == _partsCount) { + finalizeResult(); + } else { + requestParts(); + notifyAboutProgress(); + } } } // namespace Storage