From 19de122beaa7acae2aa73ecab436c286b147c7de Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 23 Aug 2019 18:03:06 +0300 Subject: [PATCH] Add Document::append_file_ids. GitOrigin-RevId: 309a322425278f09781897a8f7679ece73ecf055 --- td/telegram/Document.cpp | 26 +++++++++++++++++--------- td/telegram/Document.h | 2 ++ td/telegram/WebPagesManager.cpp | 2 +- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/td/telegram/Document.cpp b/td/telegram/Document.cpp index c7ddd7cfe..f1373c0d5 100644 --- a/td/telegram/Document.cpp +++ b/td/telegram/Document.cpp @@ -14,16 +14,27 @@ #include "td/telegram/VideoNotesManager.h" #include "td/telegram/VideosManager.h" +#include "td/utils/misc.h" + namespace td { vector Document::get_file_ids(const Td *td) const { vector result; - if (empty()) { - return result; - } - CHECK(file_id.is_valid()); + append_file_ids(td, result); + return result; +} - result.push_back(file_id); +void Document::append_file_ids(const Td *td, vector &file_ids) const { + if (!file_id.is_valid() || empty()) { + return; + } + + if (type == Type::Sticker) { + append(file_ids, td->stickers_manager_->get_sticker_file_ids(file_id)); + return; + } + + file_ids.push_back(file_id); FileId thumbnail_file_id = [&] { switch (type) { case Type::Animation: @@ -32,8 +43,6 @@ vector Document::get_file_ids(const Td *td) const { 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: @@ -43,9 +52,8 @@ vector Document::get_file_ids(const Td *td) const { } }(); if (thumbnail_file_id.is_valid()) { - result.push_back(thumbnail_file_id); + file_ids.push_back(thumbnail_file_id); } - return result; } StringBuilder &operator<<(StringBuilder &string_builder, const Document::Type &document_type) { diff --git a/td/telegram/Document.h b/td/telegram/Document.h index 9a35bdfee..37eb26e5d 100644 --- a/td/telegram/Document.h +++ b/td/telegram/Document.h @@ -31,6 +31,8 @@ struct Document { } vector get_file_ids(const Td *td) const; + + void append_file_ids(const Td *td, vector &file_ids) const; }; StringBuilder &operator<<(StringBuilder &string_builder, const Document::Type &document_type); diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index 6f141ccb6..f9331e386 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -1477,7 +1477,7 @@ 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.empty()) { - append(result, web_page->document.get_file_ids(td_)); + web_page->document.append_file_ids(td_, result); } if (!web_page->instant_view.is_empty) { for (auto &page_block : web_page->instant_view.page_blocks) {