diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index 1c13edfc9..e94beae27 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -507,9 +507,7 @@ class WebPagesManager::PageBlock { virtual Type get_type() const = 0; - virtual vector get_file_ids() const { - return vector(); - } + virtual vector get_file_ids() const = 0; virtual tl_object_ptr get_page_block_object() const = 0; @@ -570,6 +568,10 @@ class WebPagesManager::PageBlockTitle : public PageBlock { return Type::Title; } + vector get_file_ids() const override { + return get_rich_text_file_ids(title); + } + tl_object_ptr get_page_block_object() const override { return make_tl_object(get_rich_text_object(title)); } @@ -598,6 +600,10 @@ class WebPagesManager::PageBlockSubtitle : public PageBlock { return Type::Subtitle; } + vector get_file_ids() const override { + return get_rich_text_file_ids(subtitle); + } + tl_object_ptr get_page_block_object() const override { return make_tl_object(get_rich_text_object(subtitle)); } @@ -627,6 +633,10 @@ class WebPagesManager::PageBlockAuthorDate : public PageBlock { return Type::AuthorDate; } + vector get_file_ids() const override { + return get_rich_text_file_ids(author); + } + tl_object_ptr get_page_block_object() const override { return make_tl_object(get_rich_text_object(author), date); } @@ -657,6 +667,10 @@ class WebPagesManager::PageBlockHeader : public PageBlock { return Type::Header; } + vector get_file_ids() const override { + return get_rich_text_file_ids(header); + } + tl_object_ptr get_page_block_object() const override { return make_tl_object(get_rich_text_object(header)); } @@ -685,6 +699,10 @@ class WebPagesManager::PageBlockSubheader : public PageBlock { return Type::Subheader; } + vector get_file_ids() const override { + return get_rich_text_file_ids(subheader); + } + tl_object_ptr get_page_block_object() const override { return make_tl_object(get_rich_text_object(subheader)); } @@ -713,6 +731,10 @@ class WebPagesManager::PageBlockParagraph : public PageBlock { return Type::Paragraph; } + vector get_file_ids() const override { + return get_rich_text_file_ids(text); + } + tl_object_ptr get_page_block_object() const override { return make_tl_object(get_rich_text_object(text)); } @@ -742,6 +764,10 @@ class WebPagesManager::PageBlockPreformatted : public PageBlock { return Type::Preformatted; } + vector get_file_ids() const override { + return get_rich_text_file_ids(text); + } + tl_object_ptr get_page_block_object() const override { return make_tl_object(get_rich_text_object(text), language); } @@ -772,6 +798,10 @@ class WebPagesManager::PageBlockFooter : public PageBlock { return Type::Footer; } + vector get_file_ids() const override { + return get_rich_text_file_ids(footer); + } + tl_object_ptr get_page_block_object() const override { return make_tl_object(get_rich_text_object(footer)); } @@ -794,6 +824,10 @@ class WebPagesManager::PageBlockDivider : public PageBlock { return Type::Divider; } + vector get_file_ids() const override { + return {}; + } + tl_object_ptr get_page_block_object() const override { return make_tl_object(); } @@ -817,6 +851,10 @@ class WebPagesManager::PageBlockAnchor : public PageBlock { return Type::Anchor; } + vector get_file_ids() const override { + return {}; + } + tl_object_ptr get_page_block_object() const override { return make_tl_object(name); } @@ -845,6 +883,14 @@ class WebPagesManager::PageBlockList : public PageBlock { return Type::List; } + vector get_file_ids() const override { + vector result; + for (auto &item : items) { + append_rich_text_file_ids(item, result); + } + return result; + } + tl_object_ptr get_page_block_object() const override { return make_tl_object(get_rich_text_objects(items), is_ordered); } @@ -884,6 +930,13 @@ class WebPagesManager::PageBlockBlockQuote : public PageBlock { return Type::BlockQuote; } + vector get_file_ids() const override { + vector result; + append_rich_text_file_ids(text, result); + append_rich_text_file_ids(credit, result); + return result; + } + tl_object_ptr get_page_block_object() const override { return make_tl_object(get_rich_text_object(text), get_rich_text_object(credit)); } @@ -916,6 +969,13 @@ class WebPagesManager::PageBlockPullQuote : public PageBlock { return Type::PullQuote; } + vector get_file_ids() const override { + vector result; + append_rich_text_file_ids(text, result); + append_rich_text_file_ids(credit, result); + return result; + } + tl_object_ptr get_page_block_object() const override { return make_tl_object(get_rich_text_object(text), get_rich_text_object(credit)); } @@ -952,6 +1012,7 @@ class WebPagesManager::PageBlockAnimation : public PageBlock { vector get_file_ids() const override { vector result; + append_page_block_caption_file_ids(caption, result); if (animation_file_id.is_valid()) { result.push_back(animation_file_id); auto thumbnail_file_id = @@ -1024,7 +1085,9 @@ class WebPagesManager::PageBlockPhoto : public PageBlock { } vector get_file_ids() const override { - return photo_get_file_ids(photo); + auto result = photo_get_file_ids(photo); + append_page_block_caption_file_ids(caption, result); + return result; } tl_object_ptr get_page_block_object() const override { @@ -1066,6 +1129,7 @@ class WebPagesManager::PageBlockVideo : public PageBlock { vector get_file_ids() const override { vector result; + append_page_block_caption_file_ids(caption, result); if (video_file_id.is_valid()) { result.push_back(video_file_id); auto thumbnail_file_id = @@ -1185,7 +1249,9 @@ class WebPagesManager::PageBlockEmbedded : public PageBlock { } vector get_file_ids() const override { - return photo_get_file_ids(poster_photo); + auto result = photo_get_file_ids(poster_photo); + append_page_block_caption_file_ids(caption, result); + return result; } tl_object_ptr get_page_block_object() const override { @@ -1254,6 +1320,7 @@ class WebPagesManager::PageBlockEmbeddedPost : public PageBlock { for (auto &page_block : page_blocks) { append(result, page_block->get_file_ids()); } + append_page_block_caption_file_ids(caption, result); return result; } @@ -1304,6 +1371,7 @@ class WebPagesManager::PageBlockCollage : public PageBlock { for (auto &page_block : page_blocks) { append(result, page_block->get_file_ids()); } + append_page_block_caption_file_ids(caption, result); return result; } @@ -1346,6 +1414,7 @@ class WebPagesManager::PageBlockSlideshow : public PageBlock { for (auto &page_block : page_blocks) { append(result, page_block->get_file_ids()); } + append_page_block_caption_file_ids(caption, result); return result; } @@ -1434,6 +1503,7 @@ class WebPagesManager::PageBlockAudio : public PageBlock { result.push_back(thumbnail_file_id); } } + append_page_block_caption_file_ids(caption, result); return result; } @@ -3033,6 +3103,28 @@ string WebPagesManager::get_web_page_search_text(WebPageId web_page_id) const { return PSTRING() << web_page->title + " " + web_page->description; } +void WebPagesManager::append_rich_text_file_ids(const RichText &rich_text, vector &file_ids) { + if (rich_text.type == RichText::Type::InlineImage) { + CHECK(rich_text.document_file_id.is_valid()); + file_ids.push_back(rich_text.document_file_id); + } else { + for (auto &text : rich_text.texts) { + append_rich_text_file_ids(text, file_ids); + } + } +} + +void WebPagesManager::append_page_block_caption_file_ids(const PageBlockCaption &caption, vector &file_ids) { + append_rich_text_file_ids(caption.text, file_ids); + append_rich_text_file_ids(caption.credit, file_ids); +} + +vector WebPagesManager::get_rich_text_file_ids(const RichText &rich_text) { + vector result; + append_rich_text_file_ids(rich_text, result); + return result; +} + vector WebPagesManager::get_web_page_file_ids(const WebPage *web_page) { if (web_page == nullptr) { return vector(); diff --git a/td/telegram/WebPagesManager.h b/td/telegram/WebPagesManager.h index e4a8c24cc..ffe5d114d 100644 --- a/td/telegram/WebPagesManager.h +++ b/td/telegram/WebPagesManager.h @@ -232,6 +232,12 @@ class WebPagesManager : public Actor { FileSourceId get_web_page_file_source_id(WebPage *web_page); + static void append_rich_text_file_ids(const RichText &rich_text, vector &file_ids); + + static void append_page_block_caption_file_ids(const PageBlockCaption &caption, vector &file_ids); + + static vector get_rich_text_file_ids(const RichText &rich_text); + static vector get_web_page_file_ids(const WebPage *web_page); Td *td_;