Fix list item labels.

GitOrigin-RevId: c24d6efcc9f2dc36870a047a227f7af0ef93275f
This commit is contained in:
levlam 2019-02-07 21:45:08 +03:00
parent d03c74e9f7
commit 41d162f62b
2 changed files with 12 additions and 3 deletions

View File

@ -708,7 +708,7 @@ richTexts texts:vector<RichText> = 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 <cite>)
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<PageBlock> = PageBlockListItem;
//@class PageBlockHorizontalAlignment @description Describes a horizontal alignment of a table cell content

View File

@ -1102,7 +1102,8 @@ class WebPagesManager::PageBlockList : public PageBlock {
vector<Item> items;
static td_api::object_ptr<td_api::pageBlockListItem> get_page_block_list_item_object(const Item &item) {
return td_api::make_object<td_api::pageBlockListItem>(item.label, get_page_block_objects(item.page_blocks));
return td_api::make_object<td_api::pageBlockListItem>(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<PageBlockParagraph>(std::move(text_item)));
items.push_back(std::move(item));
@ -3175,6 +3177,7 @@ unique_ptr<WebPagesManager::PageBlock> WebPagesManager::get_page_block(
}
case telegram_api::pageBlockOrderedList::ID: {
auto page_block = move_tl_object_as<telegram_api::pageBlockOrderedList>(page_block_ptr);
int32 current_label = 0;
return td::make_unique<PageBlockList>(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::PageBlock> WebPagesManager::get_page_block(
if (item.page_blocks.empty()) {
item.page_blocks.push_back(make_unique<PageBlockParagraph>(RichText()));
}
++current_label;
if (item.label.empty()) {
item.label = PSTRING() << current_label << '.';
} else {
item.label += '.';
}
return item;
}));
}