Support pageBlockRelatedArticles.
GitOrigin-RevId: a527bddf568842f986c87830ce8f9d53f6a53c09
This commit is contained in:
parent
5a8566bac2
commit
e34d46ac6a
@ -738,6 +738,9 @@ pageBlockVerticalAlignmentBottom = PageBlockVerticalAlignment;
|
|||||||
//@align Horizontal cell content alignment @valign Vertical cell content alignment
|
//@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;
|
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
|
//@class PageBlock @description Describes a block of an instant view web page
|
||||||
|
|
||||||
@ -819,6 +822,9 @@ pageBlockTable caption:RichText cells:vector<vector<pageBlockTableCell>> 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
|
//@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<PageBlock> is_open:Bool = PageBlock;
|
pageBlockDetails header:RichText page_blocks:vector<PageBlock> is_open:Bool = PageBlock;
|
||||||
|
|
||||||
|
//@description Related articles @header Block header @articles List of related articles
|
||||||
|
pageBlockRelatedArticles header:RichText articles:vector<pageBlockRelatedArticle> = 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
|
//@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
|
//@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
|
||||||
|
Binary file not shown.
@ -564,6 +564,65 @@ class WebPagesManager::PageBlockTableCell {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class WebPagesManager::RelatedArticle {
|
||||||
|
public:
|
||||||
|
string url;
|
||||||
|
WebPageId web_page_id;
|
||||||
|
string title;
|
||||||
|
string description;
|
||||||
|
Photo photo;
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
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 <class T>
|
||||||
|
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 {
|
class WebPagesManager::PageBlock {
|
||||||
public:
|
public:
|
||||||
enum class Type : int32 {
|
enum class Type : int32 {
|
||||||
@ -592,7 +651,8 @@ class WebPagesManager::PageBlock {
|
|||||||
Audio,
|
Audio,
|
||||||
Kicker,
|
Kicker,
|
||||||
Table,
|
Table,
|
||||||
Details
|
Details,
|
||||||
|
RelatedArticles
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual Type get_type() const = 0;
|
virtual Type get_type() const = 0;
|
||||||
@ -1823,6 +1883,54 @@ class WebPagesManager::PageBlockDetails : public PageBlock {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class WebPagesManager::PageBlockRelatedArticles : public PageBlock {
|
||||||
|
RichText header;
|
||||||
|
vector<RelatedArticle> related_articles;
|
||||||
|
|
||||||
|
public:
|
||||||
|
PageBlockRelatedArticles() = default;
|
||||||
|
PageBlockRelatedArticles(RichText &&header, vector<RelatedArticle> &&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<FileId> &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<td_api::PageBlock> get_page_block_object() const override {
|
||||||
|
auto related_article_objects = transform(related_articles, [](const RelatedArticle &article) {
|
||||||
|
return td_api::make_object<td_api::pageBlockRelatedArticle>(
|
||||||
|
article.url, article.title, article.description,
|
||||||
|
get_photo_object(G()->td().get_actor_unsafe()->file_manager_.get(), &article.photo));
|
||||||
|
});
|
||||||
|
return make_tl_object<td_api::pageBlockRelatedArticles>(get_rich_text_object(header),
|
||||||
|
std::move(related_article_objects));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void store(T &storer) const {
|
||||||
|
using ::td::store;
|
||||||
|
store(header, storer);
|
||||||
|
store(related_articles, storer);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void parse(T &parser) {
|
||||||
|
using ::td::parse;
|
||||||
|
parse(header, parser);
|
||||||
|
parse(related_articles, parser);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <class F>
|
template <class F>
|
||||||
void WebPagesManager::PageBlock::call_impl(Type type, const PageBlock *ptr, F &&f) {
|
void WebPagesManager::PageBlock::call_impl(Type type, const PageBlock *ptr, F &&f) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -1878,6 +1986,8 @@ void WebPagesManager::PageBlock::call_impl(Type type, const PageBlock *ptr, F &&
|
|||||||
return f(static_cast<const WebPagesManager::PageBlockTable *>(ptr));
|
return f(static_cast<const WebPagesManager::PageBlockTable *>(ptr));
|
||||||
case Type::Details:
|
case Type::Details:
|
||||||
return f(static_cast<const WebPagesManager::PageBlockDetails *>(ptr));
|
return f(static_cast<const WebPagesManager::PageBlockDetails *>(ptr));
|
||||||
|
case Type::RelatedArticles:
|
||||||
|
return f(static_cast<const WebPagesManager::PageBlockRelatedArticles *>(ptr));
|
||||||
}
|
}
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
@ -3208,6 +3318,28 @@ unique_ptr<WebPagesManager::PageBlock> WebPagesManager::get_page_block(
|
|||||||
get_rich_text(std::move(page_block->title_), documents),
|
get_rich_text(std::move(page_block->title_), documents),
|
||||||
get_page_blocks(std::move(page_block->blocks_), animations, audios, documents, photos, videos), is_open);
|
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<telegram_api::pageBlockRelatedArticles>(page_block_ptr);
|
||||||
|
auto articles = transform(
|
||||||
|
std::move(page_block->articles_), [&](tl_object_ptr<telegram_api::pageRelatedArticle> &&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<PageBlockRelatedArticles>(get_rich_text(std::move(page_block->title_), documents),
|
||||||
|
std::move(articles));
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
@ -102,6 +102,7 @@ class WebPagesManager : public Actor {
|
|||||||
|
|
||||||
class PageBlockCaption;
|
class PageBlockCaption;
|
||||||
class PageBlockTableCell;
|
class PageBlockTableCell;
|
||||||
|
class RelatedArticle;
|
||||||
|
|
||||||
class PageBlock;
|
class PageBlock;
|
||||||
class PageBlockTitle;
|
class PageBlockTitle;
|
||||||
@ -130,6 +131,7 @@ class WebPagesManager : public Actor {
|
|||||||
class PageBlockAudio;
|
class PageBlockAudio;
|
||||||
class PageBlockTable;
|
class PageBlockTable;
|
||||||
class PageBlockDetails;
|
class PageBlockDetails;
|
||||||
|
class PageBlockRelatedArticles;
|
||||||
|
|
||||||
class WebPageInstantView;
|
class WebPageInstantView;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user