diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 6f9d83c6e..9e68a0913 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -3482,23 +3482,25 @@ void OverlayWidget::preloadData(int delta) { auto entity = entityByIndex(forgetIndex); if (auto photo = base::get_if>(&entity.data)) { (*photo)->unload(); - } else if (auto document = base::get_if>(&entity.data)) { - (*document)->unload(); } } + auto medias = base::flat_set>(); for (auto index = from; index != till; ++index) { auto entity = entityByIndex(index); if (auto photo = base::get_if>(&entity.data)) { (*photo)->download(fileOrigin()); } else if (auto document = base::get_if>( &entity.data)) { + const auto [i, ok] = medias.emplace( + (*document)->createMediaView()); (*document)->loadThumbnail(fileOrigin()); - //if (!(*document)->canBePlayed()) { // #TODO optimize - // (*document)->automaticLoad(fileOrigin(), entity.item); - //} + if (!(*i)->canBePlayed()) { + (*i)->automaticLoad(fileOrigin(), entity.item); + } } } + _preloadMedias = std::move(medias); } void OverlayWidget::mousePressEvent(QMouseEvent *e) { diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h index a665e48ad..7308e047b 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h @@ -349,6 +349,7 @@ private: PhotoData *_photo = nullptr; DocumentData *_doc = nullptr; std::shared_ptr _docMedia; + base::flat_set> _preloadMedias; int _rotation = 0; std::unique_ptr _sharedMedia; std::optional _sharedMediaData;