From 7dbb666a3bfb9f96fbcb58021dae3d1a65866627 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 6 Feb 2019 23:20:11 +0300 Subject: [PATCH] Support new PageBlockList. GitOrigin-RevId: 763af27e6aa32daa8a30ecb9d87a9c0e7152a5ce --- td/generate/scheme/td_api.tl | 7 +- td/generate/scheme/td_api.tlo | Bin 141688 -> 141848 bytes td/telegram/WebPagesManager.cpp | 118 +++++++++++++++++++++++++++----- 3 files changed, 107 insertions(+), 18 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 5883ba5bf..110a115b6 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -708,6 +708,9 @@ richTexts texts:vector = RichText; //@description Contains a caption of an instant view web page block, consisting of a text and a trailing credit @text Content of the caption @credit Block credit (like HTML tag ) pageBlockCaption text:RichText credit:RichText = PageBlockCaption; +//@description Describes an item of a list page block @label Item label, can be empty @page_blocks Item blocks +pageBlockListItem label:string page_blocks:vector = PageBlockListItem; + //@class PageBlock @description Describes a block of an instant view web page @@ -744,8 +747,8 @@ pageBlockDivider = PageBlock; //@description An invisible anchor on a page, which can be used in a URL to open the page from the specified anchor @name Name of the anchor pageBlockAnchor name:string = PageBlock; -//@description A list of texts @items Texts @is_ordered True, if the items should be marked with numbers -pageBlockList items:vector is_ordered:Bool = PageBlock; +//@description A list of data blocks @items The items of the list +pageBlockList items:vector = PageBlock; //@description A block quote @text Quote text @credit Quote credit pageBlockBlockQuote text:RichText credit:RichText = PageBlock; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index f1b641358b7225df99f14318fd1348d25de7111b..832e23f2f87101238c5ae97e5d3ae9c21a5924f0 100644 GIT binary patch delta 739 zcmexyiDSkU4&Fzz^{p77;MPW7eo+=N=?{XF6+}bCg7ch(1p^Y(Q=M}1le2v?i%UF9 zQgbKvNo_6>y~EGgvpG<8^Knj)@|(wmd>AKx^b?;f@m>UCfX!PK2qWdK34}4{tqNQ* z)8voe#3w&^YXi0IodSg6^3DLlsCWm}zTh2H`wf_yKQJ{0?;&cYFOX)0YU_Eg0nu;p zNoV>F4@M|Y-~-frlMhgZ86Q+6U@iywzQ~zPhr_n*AlUOupvtG${9!b(1PQ@H=&Br7 zOiZ2rA>IPyU}0c@8N~=xDE;idCTk`zq$V5Qla~MmB1jYjP%P>B2=$@CrvQkXIXOxQ6pJrVr7>UTKs5h>i70%P0s9`} zEHsCOe1#aWx#p`1BShnpZ_t3e@NEYxI6Nj7e%6P`9rzBlujYpdx?IQ)+;T5qasod~ xASQME?2rMcIh4Q!r8x!$koe>!dvzvv{LsMabdZA0EWaWqg3a2V(9I|@4*Y)lfzvmD~N_{ULtyjpRs#$qw414oFKuQ$Ao+s zCoB4kPxg2(0#TOpRt3VC^40{xIP+Eou9#`^-*4iR1>V^}qypY4Ko}+O3?PgZ@1WW* zyn|}zcn?*h^B$@u;XOpnbO#wmsL-DG8W8;lKI%-5@MMJY96mtxrhI@Zobf?L0_Jj% zAB&vXbU19=4uZXS1*&|y%wI+WOOOyO9Inc7#k76vn9f^}n4apClb@XJlUZECzyLFf z38+x|*?mpc%#zgH$%*&mr^hHV@=O-^z{1IuSsb5Vl#*IBInf;GbxRJ2LuY)1di21@ z0EmdlCv=esFp)WD93~5V5tz*JSqGxl;xp7^F`uEjH^4*;&e;IfLcQzqMFAf6ERz`* zi%&k#EHL@Z51GjuzJx%G;`j;+->)*@pn>@rC1?`9A|jDv^22Y+lQ(?*12JI3H)v?z z`L+Wha^MHl`ZM35Uh4P(jZL^z!VjEMU!YRc7c61anH*rFFkNOYEJmmN?AW~Fm(N77 LMcaB9CFTJD0WBr{ diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index 96a59b77b..061f3c952 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -913,12 +913,35 @@ class WebPagesManager::PageBlockAnchor : public PageBlock { }; class WebPagesManager::PageBlockList : public PageBlock { - vector items; - bool is_ordered = false; + public: + struct Item { + string label; + vector> page_blocks; + + template + void store(T &storer) const { + using ::td::store; + store(label, storer); + store(page_blocks, storer); + } + template + void parse(T &parser) { + using ::td::parse; + parse(label, parser); + parse(page_blocks, parser); + } + }; + + private: + vector items; + + static td_api::object_ptr get_page_block_list_item_object(const Item &item) { + return td_api::make_object(item.label, get_page_block_objects(item.page_blocks)); + } public: PageBlockList() = default; - PageBlockList(vector &&items, bool is_ordered) : items(std::move(items)), is_ordered(is_ordered) { + explicit PageBlockList(vector &&items) : items(std::move(items)) { } Type get_type() const override { @@ -927,33 +950,49 @@ class WebPagesManager::PageBlockList : public PageBlock { void append_file_ids(vector &file_ids) const override { for (auto &item : items) { - append_rich_text_file_ids(item, file_ids); + for (auto &page_block : item.page_blocks) { + page_block->append_file_ids(file_ids); + } } } tl_object_ptr get_page_block_object() const override { - return make_tl_object(get_rich_text_objects(items), is_ordered); + return td_api::make_object( + transform(items, [](const Item &item) { return get_page_block_list_item_object(item); })); } template void store(T &storer) const { using ::td::store; - - BEGIN_STORE_FLAGS(); - STORE_FLAG(is_ordered); - END_STORE_FLAGS(); - store(items, storer); } template void parse(T &parser) { using ::td::parse; - BEGIN_PARSE_FLAGS(); - PARSE_FLAG(is_ordered); - END_PARSE_FLAGS(); + if (parser.version() >= static_cast(Version::SupportInstantView2_0)) { + parse(items, parser); + } else { + vector text_items; + bool is_ordered; - parse(items, parser); + BEGIN_PARSE_FLAGS(); + PARSE_FLAG(is_ordered); + END_PARSE_FLAGS(); + + parse(text_items, parser); + + int pos = 0; + items.reserve(text_items.size()); + for (auto &text_item : text_items) { + Item item; + if (is_ordered) { + item.label = to_string(++pos); + } + item.page_blocks.push_back(make_unique(std::move(text_item))); + items.push_back(std::move(item)); + } + } } }; @@ -2697,8 +2736,55 @@ unique_ptr WebPagesManager::get_page_block( } case telegram_api::pageBlockList::ID: { auto page_block = move_tl_object_as(page_block_ptr); - return nullptr; - // return td::make_unique(get_rich_texts(std::move(page_block->items_), documents), page_block->ordered_); + return td::make_unique(transform(std::move(page_block->items_), [&](auto &&list_item_ptr) { + PageBlockList::Item item; + CHECK(list_item_ptr != nullptr); + switch (list_item_ptr->get_id()) { + case telegram_api::pageListItemText::ID: { + auto list_item = telegram_api::move_object_as(list_item_ptr); + item.page_blocks.push_back( + make_unique(get_rich_text(std::move(list_item->text_), documents))); + break; + } + case telegram_api::pageListItemBlocks::ID: { + auto list_item = telegram_api::move_object_as(list_item_ptr); + item.page_blocks = + get_page_blocks(std::move(list_item->blocks_), animations, audios, documents, photos, videos); + break; + } + } + if (item.page_blocks.empty()) { + item.page_blocks.push_back(make_unique(RichText())); + } + return item; + })); + } + case telegram_api::pageBlockOrderedList::ID: { + auto page_block = move_tl_object_as(page_block_ptr); + return td::make_unique(transform(std::move(page_block->items_), [&](auto &&list_item_ptr) { + PageBlockList::Item item; + CHECK(list_item_ptr != nullptr); + switch (list_item_ptr->get_id()) { + case telegram_api::pageListOrderedItemText::ID: { + auto list_item = telegram_api::move_object_as(list_item_ptr); + item.label = std::move(list_item->num_); + item.page_blocks.push_back( + make_unique(get_rich_text(std::move(list_item->text_), documents))); + break; + } + case telegram_api::pageListOrderedItemBlocks::ID: { + auto list_item = telegram_api::move_object_as(list_item_ptr); + item.label = std::move(list_item->num_); + item.page_blocks = + get_page_blocks(std::move(list_item->blocks_), animations, audios, documents, photos, videos); + break; + } + } + if (item.page_blocks.empty()) { + item.page_blocks.push_back(make_unique(RichText())); + } + return item; + })); } case telegram_api::pageBlockBlockquote::ID: { auto page_block = move_tl_object_as(page_block_ptr);