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 d36127cf..ce0b30d0 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 1c76173a..4b80265d 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -419,7 +419,7 @@ class WebPagesManager::RichText { Superscript, Marked, PhoneNumber, - InlineImage + Icon }; Type type = Type::Plain; string content; @@ -437,7 +437,7 @@ class WebPagesManager::RichText { store(type, storer); store(content, storer); store(texts, storer); - if (type == Type::InlineImage) { + if (type == Type::Icon) { storer.context()->td().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;