diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 5883ba5b..110a115b 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 f1b64135..832e23f2 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index 96a59b77..061f3c95 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);