From 41d162f62b127fc0babe2aa769d27180ac515efd Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 7 Feb 2019 21:45:08 +0300 Subject: [PATCH] Fix list item labels. GitOrigin-RevId: c24d6efcc9f2dc36870a047a227f7af0ef93275f --- td/generate/scheme/td_api.tl | 2 +- td/telegram/WebPagesManager.cpp | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index a9ca32835..9dad69ffc 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -708,7 +708,7 @@ 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 +//@description Describes an item of a list page block @label Item label @page_blocks Item blocks pageBlockListItem label:string page_blocks:vector = PageBlockListItem; //@class PageBlockHorizontalAlignment @description Describes a horizontal alignment of a table cell content diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index a21b3fdd1..7b413bf7c 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -1102,7 +1102,8 @@ class WebPagesManager::PageBlockList : public PageBlock { 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)); + return td_api::make_object(item.label.empty() ? "•" : item.label, + get_page_block_objects(item.page_blocks)); } public: @@ -1154,7 +1155,8 @@ class WebPagesManager::PageBlockList : public PageBlock { for (auto &text_item : text_items) { Item item; if (is_ordered) { - item.label = to_string(++pos); + pos++; + item.label = (PSTRING() << pos << '.'); } item.page_blocks.push_back(make_unique(std::move(text_item))); items.push_back(std::move(item)); @@ -3175,6 +3177,7 @@ unique_ptr WebPagesManager::get_page_block( } case telegram_api::pageBlockOrderedList::ID: { auto page_block = move_tl_object_as(page_block_ptr); + int32 current_label = 0; return td::make_unique(transform(std::move(page_block->items_), [&](auto &&list_item_ptr) { PageBlockList::Item item; CHECK(list_item_ptr != nullptr); @@ -3197,6 +3200,12 @@ unique_ptr WebPagesManager::get_page_block( if (item.page_blocks.empty()) { item.page_blocks.push_back(make_unique(RichText())); } + ++current_label; + if (item.label.empty()) { + item.label = PSTRING() << current_label << '.'; + } else { + item.label += '.'; + } return item; })); }