From 5a8566bac2a16f06b62e54632a97e9fefa5e35e6 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 7 Feb 2019 16:38:11 +0300 Subject: [PATCH] Support pageBlockDetails. GitOrigin-RevId: 82e90d7e01dc4f6bff19a64a11958fc42ff5c3a6 --- td/generate/scheme/td_api.tl | 11 +++-- td/generate/scheme/td_api.tlo | Bin 142952 -> 143128 bytes td/telegram/WebPagesManager.cpp | 75 ++++++++++++++++++++++++++++---- td/telegram/WebPagesManager.h | 1 + 4 files changed, 74 insertions(+), 13 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 858f68bf..425b8a7c 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -696,10 +696,10 @@ richTextMarked text:RichText = RichText; //@description A rich text phone number @text Text @phone_number Phone number richTextPhoneNumber text:RichText phone_number:string = RichText; -//@description A rich text inline image @document The image represented as a document. The image can be in GIF, JPEG or PNG format +//@description A small image inside the text @document The image represented as a document. The image can be in GIF, JPEG or PNG format //@width Width of a bounding box in which the image should be shown, 0 if unknown //@height Height of a bounding box in which the image should be shown, 0 if unknown -richTextInlineImage document:document width:int32 height:int32 = RichText; +richTextIcon document:document width:int32 height:int32 = RichText; //@description A concatenation of rich texts @texts Texts richTexts texts:vector = RichText; @@ -813,8 +813,11 @@ pageBlockSlideshow page_blocks:vector caption:pageBlockCaption = Page //@description A link to a chat @title Chat title @photo Chat photo; may be null @username Chat username, by which all other information about the chat should be resolved pageBlockChatLink title:string photo:chatPhoto username:string = PageBlock; -//@description A table @title Table title @cells Table cells @is_bordered True, if the table is bordered @is_striped True, if the table is striped -pageBlockTable title:RichText cells:vector> is_bordered:Bool is_striped:Bool = PageBlock; +//@description A table @caption Table caption @cells Table cells @is_bordered True, if the table is bordered @is_striped True, if the table is striped +pageBlockTable caption:RichText cells:vector> is_bordered:Bool is_striped:Bool = PageBlock; + +//@description A collapsible block @header Always visible heading for the block @page_blocks Block contents @is_open True, if the block is open by default +pageBlockDetails header:RichText page_blocks:vector is_open:Bool = PageBlock; //@description Describes an instant view page for a web page @page_blocks Content of the web page @is_rtl True, if the instant view must be shown from right to left diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index d36127cfca339480be0bad6f9c8db1aab3e6784b..ce0b30d0c664e47f23357e6d56a66268fa9eb8a8 100644 GIT binary patch delta 1520 zcmaEHhhxS)jtw%Rf(w^7mvIIprl&gP646ymAA^{6YQ1GFIUBySJ5pzBoKn%SA6Z!Jd1tMbe z3F=Om3nqQWW8DstRGWN;n(c7bVRFMyp2-KkuuNX_SqEbCozD>0P5Kf55eWGLb#BF% z9EivZm_ns7!@X; z_+G#Y3O|O)ieL00Dhqxzc-X1iBcfO z0L+-4qrj*D6T+TMK<=1+gg9j~ii|2mm{y_4s6m9X8;V4^%|M9}n$=(_esY1e4#ay4 zlwdXi%0#)ig*asol!?%G&jhOS%0AlC`n8=rpE)Wr$ zPf&NlTrlY~9_x0Hq}t>&)NF^d4wD;x@=QMPg=O-Z&pHsB?|g>1ZqkJw6Ywr6i zAbb~+n3R(W_8llYuz<1yBq`MVS^#mxmESI45n$AS>CHBON}z7v@;3q^B=GNs5=5Io zi~*Q2T|tpi0Vae!PC>bDdIfRHE+{gp5Mi2*5~BtY%6gQL+-89-_alpel7#&g$5QU1 z%;b!a)QXbOq8yO?WLTn|TwtvO@pOnX%zl{M^aaX{77)oh%0&6WLWL-0Q&f=rfVETs zhwmG>X+Rfo!o4-waD%ZSoCi#+AW!Z$(*7?D^Q329PG(-JXD%=sfYgCf2lM2KInt9W s&IwGO^UY>*gCPgRUp#7zkd!f9M~%?{r&G3td().get_actor_unsafe()->documents_manager_->store_document(document_file_id, storer); } if (type == Type::Url) { @@ -451,7 +451,7 @@ class WebPagesManager::RichText { parse(type, parser); parse(content, parser); parse(texts, parser); - if (type == Type::InlineImage) { + if (type == Type::Icon) { document_file_id = parser.context()->td().get_actor_unsafe()->documents_manager_->parse_document(parser); if (!document_file_id.is_valid()) { LOG(ERROR) << "Failed to load document from database"; @@ -591,7 +591,8 @@ class WebPagesManager::PageBlock { ChatLink, Audio, Kicker, - Table + Table, + Details }; virtual Type get_type() const = 0; @@ -1774,6 +1775,54 @@ class WebPagesManager::PageBlockTable : public PageBlock { } }; +class WebPagesManager::PageBlockDetails : public PageBlock { + RichText header; + vector> page_blocks; + bool is_open; + + public: + PageBlockDetails() = default; + PageBlockDetails(RichText &&header, vector> &&page_blocks, bool is_open) + : header(std::move(header)), page_blocks(std::move(page_blocks)), is_open(is_open) { + } + + Type get_type() const override { + return Type::Details; + } + + void append_file_ids(vector &file_ids) const override { + append_rich_text_file_ids(header, file_ids); + for (auto &page_block : 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_object(header), get_page_block_objects(page_blocks), + is_open); + } + + template + void store(T &storer) const { + using ::td::store; + BEGIN_STORE_FLAGS(); + STORE_FLAG(is_open); + END_STORE_FLAGS(); + store(header, storer); + store(page_blocks, storer); + } + + template + void parse(T &parser) { + using ::td::parse; + BEGIN_PARSE_FLAGS(); + PARSE_FLAG(is_open); + END_PARSE_FLAGS(); + parse(header, parser); + parse(page_blocks, parser); + } +}; + template void WebPagesManager::PageBlock::call_impl(Type type, const PageBlock *ptr, F &&f) { switch (type) { @@ -1827,6 +1876,8 @@ void WebPagesManager::PageBlock::call_impl(Type type, const PageBlock *ptr, F && return f(static_cast(ptr)); case Type::Table: return f(static_cast(ptr)); + case Type::Details: + return f(static_cast(ptr)); } UNREACHABLE(); } @@ -2746,7 +2797,7 @@ WebPagesManager::RichText WebPagesManager::get_rich_text(tl_object_ptr(rich_text_ptr); auto it = documents.find(rich_text->document_id_); if (it != documents.end()) { - result.type = RichText::Type::InlineImage; + result.type = RichText::Type::Icon; result.document_file_id = it->second; Dimensions dimensions = get_dimensions(rich_text->w_, rich_text->h_); result.content = PSTRING() << (dimensions.width * static_cast(65536) + dimensions.height); @@ -2797,11 +2848,11 @@ tl_object_ptr WebPagesManager::get_rich_text_object(const Rich return make_tl_object(get_rich_text_object(rich_text.texts[0])); case RichText::Type::PhoneNumber: return make_tl_object(get_rich_text_object(rich_text.texts[0]), rich_text.content); - case RichText::Type::InlineImage: { + case RichText::Type::Icon: { auto dimensions = to_integer(rich_text.content); auto width = static_cast(dimensions / 65536); auto height = static_cast(dimensions % 65536); - return make_tl_object( + return make_tl_object( G()->td().get_actor_unsafe()->documents_manager_->get_document_object(rich_text.document_file_id), width, height); } @@ -3150,7 +3201,13 @@ unique_ptr WebPagesManager::get_page_block( return td::make_unique(get_rich_text(std::move(page_block->title_), documents), std::move(cells), is_bordered, is_striped); } - + case telegram_api::pageBlockDetails::ID: { + auto page_block = move_tl_object_as(page_block_ptr); + auto is_open = (page_block->flags_ & telegram_api::pageBlockDetails::OPEN_MASK) != 0; + return td::make_unique( + get_rich_text(std::move(page_block->title_), documents), + get_page_blocks(std::move(page_block->blocks_), animations, audios, documents, photos, videos), is_open); + } default: UNREACHABLE(); } @@ -3466,7 +3523,7 @@ string WebPagesManager::get_web_page_search_text(WebPageId web_page_id) const { } void WebPagesManager::append_rich_text_file_ids(const RichText &rich_text, vector &file_ids) { - if (rich_text.type == RichText::Type::InlineImage) { + if (rich_text.type == RichText::Type::Icon) { CHECK(rich_text.document_file_id.is_valid()); file_ids.push_back(rich_text.document_file_id); } else { diff --git a/td/telegram/WebPagesManager.h b/td/telegram/WebPagesManager.h index d6dde92c..1564ed37 100644 --- a/td/telegram/WebPagesManager.h +++ b/td/telegram/WebPagesManager.h @@ -129,6 +129,7 @@ class WebPagesManager : public Actor { class PageBlockChatLink; class PageBlockAudio; class PageBlockTable; + class PageBlockDetails; class WebPageInstantView;