diff --git a/td/telegram/Document.cpp b/td/telegram/Document.cpp index 92e26e92..4aac60f4 100644 --- a/td/telegram/Document.cpp +++ b/td/telegram/Document.cpp @@ -6,8 +6,49 @@ // #include "td/telegram/Document.h" +#include "td/telegram/AnimationsManager.h" +#include "td/telegram/AudiosManager.h" +#include "td/telegram/DocumentsManager.h" +#include "td/telegram/StickersManager.h" +#include "td/telegram/Td.h" +#include "td/telegram/VideosManager.h" +#include "td/telegram/VideoNotesManager.h" +#include "td/telegram/VoiceNotesManager.h" + namespace td { +vector Document::get_file_ids(const Td *td) const { + vector result; + if (empty()) { + return result; + } + CHECK(file_id.is_valid()); + + result.push_back(file_id); + FileId thumbnail_file_id = [&] { + switch (type) { + case Type::Animation: + return td->animations_manager_->get_animation_thumbnail_file_id(file_id); + case Type::Audio: + return td->audios_manager_->get_audio_thumbnail_file_id(file_id); + case Type::General: + return td->documents_manager_->get_document_thumbnail_file_id(file_id); + case Type::Sticker: + return td->stickers_manager_->get_sticker_thumbnail_file_id(file_id); + case Type::Video: + return td->videos_manager_->get_video_thumbnail_file_id(file_id); + case Type::VideoNote: + return td->video_notes_manager_->get_video_note_thumbnail_file_id(file_id); + default: + return FileId(); + } + }(); + if (thumbnail_file_id.is_valid()) { + result.push_back(thumbnail_file_id); + } + return result; +} + StringBuilder &operator<<(StringBuilder &string_builder, const Document &document) { auto type = [&] { switch (document.type) { diff --git a/td/telegram/Document.h b/td/telegram/Document.h index 44f0fd56..53393104 100644 --- a/td/telegram/Document.h +++ b/td/telegram/Document.h @@ -13,6 +13,8 @@ namespace td { +class Td; + struct Document { // append only enum class Type : int32 { Unknown, Animation, Audio, General, Sticker, Video, VideoNote, VoiceNote }; @@ -27,6 +29,8 @@ struct Document { bool empty() const { return type == Type::Unknown; } + + vector get_file_ids(const Td *td) const; }; StringBuilder &operator<<(StringBuilder &string_builder, const Document &document); diff --git a/td/telegram/Document.hpp b/td/telegram/Document.hpp index a0a5011f..b703c6bc 100644 --- a/td/telegram/Document.hpp +++ b/td/telegram/Document.hpp @@ -9,14 +9,21 @@ #include "td/telegram/Document.h" #include "td/telegram/AnimationsManager.h" +#include "td/telegram/AnimationsManager.hpp" #include "td/telegram/AudiosManager.h" +#include "td/telegram/AudiosManager.hpp" #include "td/telegram/DocumentsManager.h" +#include "td/telegram/DocumentsManager.hpp" #include "td/telegram/files/FileId.hpp" #include "td/telegram/StickersManager.h" +#include "td/telegram/StickersManager.hpp" #include "td/telegram/Td.h" #include "td/telegram/VideosManager.h" +#include "td/telegram/VideosManager.hpp" #include "td/telegram/VideoNotesManager.h" +#include "td/telegram/VideoNotesManager.hpp" #include "td/telegram/VoiceNotesManager.h" +#include "td/telegram/VoiceNotesManager.hpp" #include "td/utils/logging.h" #include "td/utils/tl_helpers.h" diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index 0725da5b..d9c706fe 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -3765,34 +3765,8 @@ vector WebPagesManager::get_web_page_file_ids(const WebPage *web_page) c } vector result = photo_get_file_ids(web_page->photo); - if (web_page->document.file_id.is_valid()) { - result.push_back(web_page->document.file_id); - FileId thumbnail_file_id; - switch (web_page->document.type) { - case Document::Type::Animation: - thumbnail_file_id = td_->animations_manager_->get_animation_thumbnail_file_id(web_page->document.file_id); - break; - case Document::Type::Audio: - thumbnail_file_id = td_->audios_manager_->get_audio_thumbnail_file_id(web_page->document.file_id); - break; - case Document::Type::General: - thumbnail_file_id = td_->documents_manager_->get_document_thumbnail_file_id(web_page->document.file_id); - break; - case Document::Type::Sticker: - thumbnail_file_id = td_->stickers_manager_->get_sticker_thumbnail_file_id(web_page->document.file_id); - break; - case Document::Type::Video: - thumbnail_file_id = td_->videos_manager_->get_video_thumbnail_file_id(web_page->document.file_id); - break; - case Document::Type::VideoNote: - thumbnail_file_id = td_->video_notes_manager_->get_video_note_thumbnail_file_id(web_page->document.file_id); - break; - default: - break; - } - if (thumbnail_file_id.is_valid()) { - result.push_back(thumbnail_file_id); - } + if (!web_page->document.empty()) { + append(result, web_page->document.get_file_ids(td_)); } if (!web_page->instant_view.is_empty) { for (auto &page_block : web_page->instant_view.page_blocks) {