From e34d46ac6afde158cd4beace318e2e35c5f9d065 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 7 Feb 2019 17:44:09 +0300 Subject: [PATCH] Support pageBlockRelatedArticles. GitOrigin-RevId: a527bddf568842f986c87830ce8f9d53f6a53c09 --- td/generate/scheme/td_api.tl | 6 ++ td/generate/scheme/td_api.tlo | Bin 143128 -> 143528 bytes td/telegram/WebPagesManager.cpp | 134 +++++++++++++++++++++++++++++++- td/telegram/WebPagesManager.h | 2 + 4 files changed, 141 insertions(+), 1 deletion(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 425b8a7c..64dc8f80 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -738,6 +738,9 @@ pageBlockVerticalAlignmentBottom = PageBlockVerticalAlignment; //@align Horizontal cell content alignment @valign Vertical cell content alignment pageBlockTableCell text:RichText is_header:Bool colspan:int32 rowspan:int32 align:PageBlockHorizontalAlignment valign:PageBlockVerticalAlignment = PageBlockTableCell; +//@description Contains information about a related article @url Related article URL @title Article title; can be empty @param_description Article description, can be empty @photo Article photo; may be null +pageBlockRelatedArticle url:string title:string description:string photo:photo = PageBlockRelatedArticle; + //@class PageBlock @description Describes a block of an instant view web page @@ -819,6 +822,9 @@ pageBlockTable caption:RichText cells:vector> is_bord //@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 Related articles @header Block header @articles List of related articles +pageBlockRelatedArticles header:RichText articles:vector = 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 //@is_full True, if the instant view contains the full page. A network request might be needed to get the full web page instant view diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index ce0b30d0c664e47f23357e6d56a66268fa9eb8a8..f34ab6666c3fb8396aaaa2c71d6a1ed643fd1646 100644 GIT binary patch delta 865 zcmbPnk7LC{4&Fzz^{p77;NC`Feo?{hGe;kB1|+7ZI_2aiXEQKJPyWa#KG{Wdj?CU~ z7i+}fGC`?1i6yBijzuMz$vLSLCrE65AnGE(IDNCK+UDadAX6sad20Y+2)t8)Ff87g zKo|w@R5(FuZXOfzVVb<~yZGc49|R^Jd8Y%B{_;)%!jO0mHNxjT)QFPzP$Sm7hpM>% zQ^WEBqGtLAB}S;Wgbx}JgC2a+nI7TCsL2d+*pm-XtsEbr>TEu$NWk0!3XURYHXRPz zwu4}QRD6Ugp952V0VeY0qYK1*n@>>pJ@^y=5!rzuV)7ZP#^J2P8{8dl|r*j-OfaE}?vrIPpraaxD bk1=6#!F3K6knrXce@!NX-Mwuhqr^M_C_t+t delta 678 zcmZ4SkYmO@4&Fzz^{p77;O<6Veo?`N%bUwM0}|6yopSP%vl$qqCVylUpX?$!XS0Zy zivZ))&5>%GkF$VOO%`}(0AaYiQ-LsY-kCrcOJE{r-bFw}G~O#f7(VZzx*Fa?b**?0 z)%5_ThUEiPjl~D3ngp20ln)vZa}In6fiNUKLQS^$2-Q{aQAGme!kfp0d_bNna%R)v zux&dCcJ&&V@(VEKET5nTXnb;k7+LTMYVCm!I+GnfLpg7-ie|v1Cw#7f=oa{*zzMUS zY4YDj<;gK$ppNeN0<~(*mmG*76fIEk6^1(jk$#=d_fJhbmfQHzTA5cFg{Dj5@T*~4n zPN_3csp$r*8FeNr{PKX9n)3_lr3t?dKtw`*L(Qo94UM!bzachnUh?M-)SWH=6gH>) P*O&~}vVFoNMu~X + void store(T &storer) const { + using ::td::store; + bool has_title = !title.empty(); + bool has_description = !description.empty(); + bool has_photo = photo.id != -2; + BEGIN_STORE_FLAGS(); + STORE_FLAG(has_title); + STORE_FLAG(has_description); + STORE_FLAG(has_photo); + END_STORE_FLAGS(); + store(url, storer); + store(web_page_id, storer); + if (has_title) { + store(title, storer); + } + if (has_description) { + store(description, storer); + } + if (has_photo) { + store(photo, storer); + } + } + + template + void parse(T &parser) { + using ::td::parse; + bool has_title; + bool has_description; + bool has_photo; + BEGIN_PARSE_FLAGS(); + PARSE_FLAG(has_title); + PARSE_FLAG(has_description); + PARSE_FLAG(has_photo); + END_PARSE_FLAGS(); + parse(url, parser); + parse(web_page_id, parser); + if (has_title) { + parse(title, parser); + } + if (has_description) { + parse(description, parser); + } + if (has_photo) { + parse(photo, parser); + } else { + photo.id = -2; + } + } +}; + class WebPagesManager::PageBlock { public: enum class Type : int32 { @@ -592,7 +651,8 @@ class WebPagesManager::PageBlock { Audio, Kicker, Table, - Details + Details, + RelatedArticles }; virtual Type get_type() const = 0; @@ -1823,6 +1883,54 @@ class WebPagesManager::PageBlockDetails : public PageBlock { } }; +class WebPagesManager::PageBlockRelatedArticles : public PageBlock { + RichText header; + vector related_articles; + + public: + PageBlockRelatedArticles() = default; + PageBlockRelatedArticles(RichText &&header, vector &&related_articles) + : header(std::move(header)), related_articles(std::move(related_articles)) { + } + + Type get_type() const override { + return Type::RelatedArticles; + } + + void append_file_ids(vector &file_ids) const override { + append_rich_text_file_ids(header, file_ids); + for (auto &article : related_articles) { + if (article.photo.id != -2) { + append(file_ids, photo_get_file_ids(article.photo)); + } + } + } + + tl_object_ptr get_page_block_object() const override { + auto related_article_objects = transform(related_articles, [](const RelatedArticle &article) { + return td_api::make_object( + article.url, article.title, article.description, + get_photo_object(G()->td().get_actor_unsafe()->file_manager_.get(), &article.photo)); + }); + return make_tl_object(get_rich_text_object(header), + std::move(related_article_objects)); + } + + template + void store(T &storer) const { + using ::td::store; + store(header, storer); + store(related_articles, storer); + } + + template + void parse(T &parser) { + using ::td::parse; + parse(header, parser); + parse(related_articles, parser); + } +}; + template void WebPagesManager::PageBlock::call_impl(Type type, const PageBlock *ptr, F &&f) { switch (type) { @@ -1878,6 +1986,8 @@ void WebPagesManager::PageBlock::call_impl(Type type, const PageBlock *ptr, F && return f(static_cast(ptr)); case Type::Details: return f(static_cast(ptr)); + case Type::RelatedArticles: + return f(static_cast(ptr)); } UNREACHABLE(); } @@ -3208,6 +3318,28 @@ unique_ptr WebPagesManager::get_page_block( get_rich_text(std::move(page_block->title_), documents), get_page_blocks(std::move(page_block->blocks_), animations, audios, documents, photos, videos), is_open); } + case telegram_api::pageBlockRelatedArticles::ID: { + auto page_block = move_tl_object_as(page_block_ptr); + auto articles = transform( + std::move(page_block->articles_), [&](tl_object_ptr &&related_article) { + RelatedArticle article; + article.url = std::move(related_article->url_); + article.web_page_id = WebPageId(related_article->webpage_id_); + article.title = std::move(related_article->title_); + article.description = std::move(related_article->description_); + auto it = (related_article->flags_ & telegram_api::pageRelatedArticle::PHOTO_ID_MASK) != 0 + ? photos.find(related_article->photo_id_) + : photos.end(); + if (it == photos.end()) { + article.photo.id = -2; + } else { + article.photo = it->second; + } + return article; + }); + return td::make_unique(get_rich_text(std::move(page_block->title_), documents), + std::move(articles)); + } default: UNREACHABLE(); } diff --git a/td/telegram/WebPagesManager.h b/td/telegram/WebPagesManager.h index 1564ed37..35b02047 100644 --- a/td/telegram/WebPagesManager.h +++ b/td/telegram/WebPagesManager.h @@ -102,6 +102,7 @@ class WebPagesManager : public Actor { class PageBlockCaption; class PageBlockTableCell; + class RelatedArticle; class PageBlock; class PageBlockTitle; @@ -130,6 +131,7 @@ class WebPagesManager : public Actor { class PageBlockAudio; class PageBlockTable; class PageBlockDetails; + class PageBlockRelatedArticles; class WebPageInstantView;