From ccc61028b8f4a2b11fe074d0f4e9576728985a14 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 18 Aug 2023 19:39:22 +0200 Subject: [PATCH] Allow downloading files from webpage collages. --- .../data/data_download_manager.cpp | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/data/data_download_manager.cpp b/Telegram/SourceFiles/data/data_download_manager.cpp index 088dc0b92d..c1a0719feb 100644 --- a/Telegram/SourceFiles/data/data_download_manager.cpp +++ b/Telegram/SourceFiles/data/data_download_manager.cpp @@ -86,6 +86,45 @@ constexpr auto ByDocument = [](const auto &entry) { return nullptr; } +[[nodiscard]] bool ItemContainsMedia(const DownloadObject &object) { + if (const auto photo = object.photo) { + if (const auto media = object.item->media()) { + if (const auto page = media->webpage()) { + if (page->photo == photo) { + return true; + } + for (const auto &item : page->collage.items) { + if (const auto v = std::get_if(&item)) { + if ((*v) == photo) { + return true; + } + } + } + } else { + return (media->photo() == photo); + } + } + } else if (const auto document = object.document) { + if (const auto media = object.item->media()) { + if (const auto page = media->webpage()) { + if (page->document == document) { + return true; + } + for (const auto &item : page->collage.items) { + if (const auto v = std::get_if(&item)) { + if ((*v) == document) { + return true; + } + } + } + } else { + return (media->document() == document); + } + } + } + return false; +} + struct DocumentDescriptor { uint64 sessionUniqueId = 0; DocumentId documentId = 0; @@ -242,12 +281,12 @@ void DownloadManager::check( std::vector::iterator i) { auto &entry = *i; - const auto photo = ItemPhoto(entry.object.item); - const auto document = ItemDocument(entry.object.item); - if (entry.object.photo != photo || entry.object.document != document) { + if (!ItemContainsMedia(entry.object)) { cancel(data, i); return; } + const auto document = entry.object.document; + // Load with progress only documents for now. Assert(document != nullptr);