Support new PageBlockList.
GitOrigin-RevId: 763af27e6aa32daa8a30ecb9d87a9c0e7152a5ce
This commit is contained in:
parent
4017c2098c
commit
7dbb666a3b
@ -708,6 +708,9 @@ 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>)
|
//@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;
|
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<PageBlock> = PageBlockListItem;
|
||||||
|
|
||||||
|
|
||||||
//@class PageBlock @description Describes a block of an instant view web page
|
//@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
|
//@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;
|
pageBlockAnchor name:string = PageBlock;
|
||||||
|
|
||||||
//@description A list of texts @items Texts @is_ordered True, if the items should be marked with numbers
|
//@description A list of data blocks @items The items of the list
|
||||||
pageBlockList items:vector<RichText> is_ordered:Bool = PageBlock;
|
pageBlockList items:vector<pageBlockListItem> = PageBlock;
|
||||||
|
|
||||||
//@description A block quote @text Quote text @credit Quote credit
|
//@description A block quote @text Quote text @credit Quote credit
|
||||||
pageBlockBlockQuote text:RichText credit:RichText = PageBlock;
|
pageBlockBlockQuote text:RichText credit:RichText = PageBlock;
|
||||||
|
Binary file not shown.
@ -913,12 +913,35 @@ class WebPagesManager::PageBlockAnchor : public PageBlock {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class WebPagesManager::PageBlockList : public PageBlock {
|
class WebPagesManager::PageBlockList : public PageBlock {
|
||||||
vector<RichText> items;
|
public:
|
||||||
bool is_ordered = false;
|
struct Item {
|
||||||
|
string label;
|
||||||
|
vector<unique_ptr<PageBlock>> page_blocks;
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void store(T &storer) const {
|
||||||
|
using ::td::store;
|
||||||
|
store(label, storer);
|
||||||
|
store(page_blocks, storer);
|
||||||
|
}
|
||||||
|
template <class T>
|
||||||
|
void parse(T &parser) {
|
||||||
|
using ::td::parse;
|
||||||
|
parse(label, parser);
|
||||||
|
parse(page_blocks, parser);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PageBlockList() = default;
|
PageBlockList() = default;
|
||||||
PageBlockList(vector<RichText> &&items, bool is_ordered) : items(std::move(items)), is_ordered(is_ordered) {
|
explicit PageBlockList(vector<Item> &&items) : items(std::move(items)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Type get_type() const override {
|
Type get_type() const override {
|
||||||
@ -927,33 +950,49 @@ class WebPagesManager::PageBlockList : public PageBlock {
|
|||||||
|
|
||||||
void append_file_ids(vector<FileId> &file_ids) const override {
|
void append_file_ids(vector<FileId> &file_ids) const override {
|
||||||
for (auto &item : items) {
|
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<td_api::PageBlock> get_page_block_object() const override {
|
tl_object_ptr<td_api::PageBlock> get_page_block_object() const override {
|
||||||
return make_tl_object<td_api::pageBlockList>(get_rich_text_objects(items), is_ordered);
|
return td_api::make_object<td_api::pageBlockList>(
|
||||||
|
transform(items, [](const Item &item) { return get_page_block_list_item_object(item); }));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void store(T &storer) const {
|
void store(T &storer) const {
|
||||||
using ::td::store;
|
using ::td::store;
|
||||||
|
|
||||||
BEGIN_STORE_FLAGS();
|
|
||||||
STORE_FLAG(is_ordered);
|
|
||||||
END_STORE_FLAGS();
|
|
||||||
|
|
||||||
store(items, storer);
|
store(items, storer);
|
||||||
}
|
}
|
||||||
template <class T>
|
template <class T>
|
||||||
void parse(T &parser) {
|
void parse(T &parser) {
|
||||||
using ::td::parse;
|
using ::td::parse;
|
||||||
|
|
||||||
BEGIN_PARSE_FLAGS();
|
if (parser.version() >= static_cast<int32>(Version::SupportInstantView2_0)) {
|
||||||
PARSE_FLAG(is_ordered);
|
parse(items, parser);
|
||||||
END_PARSE_FLAGS();
|
} else {
|
||||||
|
vector<RichText> 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<PageBlockParagraph>(std::move(text_item)));
|
||||||
|
items.push_back(std::move(item));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2697,8 +2736,55 @@ unique_ptr<WebPagesManager::PageBlock> WebPagesManager::get_page_block(
|
|||||||
}
|
}
|
||||||
case telegram_api::pageBlockList::ID: {
|
case telegram_api::pageBlockList::ID: {
|
||||||
auto page_block = move_tl_object_as<telegram_api::pageBlockList>(page_block_ptr);
|
auto page_block = move_tl_object_as<telegram_api::pageBlockList>(page_block_ptr);
|
||||||
return nullptr;
|
return td::make_unique<PageBlockList>(transform(std::move(page_block->items_), [&](auto &&list_item_ptr) {
|
||||||
// return td::make_unique<PageBlockList>(get_rich_texts(std::move(page_block->items_), documents), page_block->ordered_);
|
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<telegram_api::pageListItemText>(list_item_ptr);
|
||||||
|
item.page_blocks.push_back(
|
||||||
|
make_unique<PageBlockParagraph>(get_rich_text(std::move(list_item->text_), documents)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case telegram_api::pageListItemBlocks::ID: {
|
||||||
|
auto list_item = telegram_api::move_object_as<telegram_api::pageListItemBlocks>(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<PageBlockParagraph>(RichText()));
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
case telegram_api::pageBlockOrderedList::ID: {
|
||||||
|
auto page_block = move_tl_object_as<telegram_api::pageBlockOrderedList>(page_block_ptr);
|
||||||
|
return td::make_unique<PageBlockList>(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<telegram_api::pageListOrderedItemText>(list_item_ptr);
|
||||||
|
item.label = std::move(list_item->num_);
|
||||||
|
item.page_blocks.push_back(
|
||||||
|
make_unique<PageBlockParagraph>(get_rich_text(std::move(list_item->text_), documents)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case telegram_api::pageListOrderedItemBlocks::ID: {
|
||||||
|
auto list_item = telegram_api::move_object_as<telegram_api::pageListOrderedItemBlocks>(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<PageBlockParagraph>(RichText()));
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
case telegram_api::pageBlockBlockquote::ID: {
|
case telegram_api::pageBlockBlockquote::ID: {
|
||||||
auto page_block = move_tl_object_as<telegram_api::pageBlockBlockquote>(page_block_ptr);
|
auto page_block = move_tl_object_as<telegram_api::pageBlockBlockquote>(page_block_ptr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user