Add strongly-typed linkPreviewTypeStickerSet.

This commit is contained in:
levlam 2024-07-03 15:49:53 +03:00
parent 51d0e70b9e
commit 3872aa26d1
3 changed files with 44 additions and 19 deletions

View File

@ -2551,13 +2551,24 @@ pageBlockMap location:location zoom:int32 width:int32 height:int32 caption:pageB
webPageInstantView page_blocks:vector<PageBlock> view_count:int32 version:int32 is_rtl:Bool is_full:Bool feedback_link:InternalLinkType = WebPageInstantView;
//@class LinkPreviewType @description Describes type of a link preview
//@description The link is a link to a sticker set
//@stickers Up to 4 stickers from the sticker set
linkPreviewTypeStickerSet stickers:vector<sticker> = LinkPreviewType;
//@description The link preview type is unsupported yet
//@type String type of the link preview. Can be: article, photo, audio, video, document, profile, app, or something else
linkPreviewTypeOther type:string = LinkPreviewType;
//@description Describes a link preview
//@url Original URL of the link
//@display_url URL to display
//@type Type of the link preview. Can be: article, photo, audio, video, document, profile, app, or something else
//@site_name Short name of the site (e.g., Google Docs, App Store)
//@title Title of the content
//@param_description Description of the content
//@type Type of the link preview
//@photo Image representing the content; may be null
//@embed_url URL to show in the embedded preview
//@embed_type MIME type of the embedded preview, (e.g., text/html or video/mp4)
@ -2578,9 +2589,8 @@ webPageInstantView page_blocks:vector<PageBlock> view_count:int32 version:int32
//@voice_note Preview of the content as a voice note, if available; may be null
//@story_sender_chat_id The identifier of the sender of the previewed story; 0 if none
//@story_id The identifier of the previewed story; 0 if none
//@stickers Up to 4 stickers from the sticker set available via the link
//@instant_view_version Version of instant view (currently, can be 1 or 2) for the web page; 0 if none
linkPreview url:string display_url:string type:string site_name:string title:string description:formattedText photo:photo embed_url:string embed_type:string embed_width:int32 embed_height:int32 duration:int32 author:string has_large_media:Bool show_large_media:Bool skip_confirmation:Bool show_above_text:Bool animation:animation audio:audio document:document sticker:sticker video:video video_note:videoNote voice_note:voiceNote story_sender_chat_id:int53 story_id:int32 stickers:vector<sticker> instant_view_version:int32 = LinkPreview;
linkPreview url:string display_url:string site_name:string title:string description:formattedText type:LinkPreviewType photo:photo embed_url:string embed_type:string embed_width:int32 embed_height:int32 duration:int32 author:string has_large_media:Bool show_large_media:Bool skip_confirmation:Bool show_above_text:Bool animation:animation audio:audio document:document sticker:sticker video:video video_note:videoNote voice_note:voiceNote story_sender_chat_id:int53 story_id:int32 instant_view_version:int32 = LinkPreview;
//@description Contains information about a country

View File

@ -1333,11 +1333,23 @@ bool WebPagesManager::have_web_page(WebPageId web_page_id) const {
return get_web_page(web_page_id) != nullptr;
}
tl_object_ptr<td_api::linkPreview> WebPagesManager::get_link_preview_object(WebPageId web_page_id,
bool force_small_media,
bool force_large_media,
bool skip_confirmation,
bool invert_media) const {
td_api::object_ptr<td_api::LinkPreviewType> WebPagesManager::get_link_preview_type_object(
const WebPage *web_page, bool force_small_media, bool force_large_media) const {
if (web_page->type_ == "telegram_stickerset") {
auto stickers = transform(web_page->sticker_ids_, [&](FileId sticker_id) {
return td_->stickers_manager_->get_sticker_object(sticker_id);
});
return td_api::make_object<td_api::linkPreviewTypeStickerSet>(std::move(stickers));
}
// TODO LOG(ERROR) << "Receive link preview of unsupported type " << web_page->type_;
return td_api::make_object<td_api::linkPreviewTypeOther>(web_page->type_);
}
td_api::object_ptr<td_api::linkPreview> WebPagesManager::get_link_preview_object(WebPageId web_page_id,
bool force_small_media,
bool force_large_media,
bool skip_confirmation,
bool invert_media) const {
if (!web_page_id.is_valid()) {
return nullptr;
}
@ -1470,11 +1482,10 @@ tl_object_ptr<td_api::linkPreview> WebPagesManager::get_link_preview_object(WebP
}
return false;
}();
auto stickers = transform(web_page->sticker_ids_,
[&](FileId sticker_id) { return td_->stickers_manager_->get_sticker_object(sticker_id); });
return td_api::make_object<td_api::linkPreview>(
web_page->url_, web_page->display_url_, web_page->type_, web_page->site_name_, web_page->title_,
web_page->url_, web_page->display_url_, web_page->site_name_, web_page->title_,
get_formatted_text_object(description, true, duration == 0 ? std::numeric_limits<int32>::max() : duration),
get_link_preview_type_object(web_page, force_small_media, force_large_media),
get_photo_object(td_->file_manager_.get(), web_page->photo_), web_page->embed_url_, web_page->embed_type_,
web_page->embed_dimensions_.width, web_page->embed_dimensions_.height, web_page->duration_, web_page->author_,
web_page->has_large_media_, show_large_media, skip_confirmation, invert_media,
@ -1499,11 +1510,11 @@ tl_object_ptr<td_api::linkPreview> WebPagesManager::get_link_preview_object(WebP
web_page->document_.type == Document::Type::VoiceNote
? td_->voice_notes_manager_->get_voice_note_object(web_page->document_.file_id)
: nullptr,
td_->dialog_manager_->get_chat_id_object(story_sender_dialog_id, "webPage"), story_id.get(), std::move(stickers),
td_->dialog_manager_->get_chat_id_object(story_sender_dialog_id, "webPage"), story_id.get(),
instant_view_version);
}
tl_object_ptr<td_api::webPageInstantView> WebPagesManager::get_web_page_instant_view_object(
td_api::object_ptr<td_api::webPageInstantView> WebPagesManager::get_web_page_instant_view_object(
WebPageId web_page_id) const {
const WebPage *web_page = get_web_page(web_page_id);
if (web_page == nullptr || web_page->instant_view_.is_empty_) {
@ -1512,7 +1523,7 @@ tl_object_ptr<td_api::webPageInstantView> WebPagesManager::get_web_page_instant_
return get_web_page_instant_view_object(web_page_id, &web_page->instant_view_, web_page->url_);
}
tl_object_ptr<td_api::webPageInstantView> WebPagesManager::get_web_page_instant_view_object(
td_api::object_ptr<td_api::webPageInstantView> WebPagesManager::get_web_page_instant_view_object(
WebPageId web_page_id, const WebPageInstantView *web_page_instant_view, Slice web_page_url) const {
if (web_page_instant_view == nullptr) {
return nullptr;

View File

@ -75,11 +75,11 @@ class WebPagesManager final : public Actor {
bool have_web_page_force(WebPageId web_page_id);
tl_object_ptr<td_api::linkPreview> get_link_preview_object(WebPageId web_page_id, bool force_small_media,
bool force_large_media, bool skip_confirmation,
bool invert_media) const;
td_api::object_ptr<td_api::linkPreview> get_link_preview_object(WebPageId web_page_id, bool force_small_media,
bool force_large_media, bool skip_confirmation,
bool invert_media) const;
tl_object_ptr<td_api::webPageInstantView> get_web_page_instant_view_object(WebPageId web_page_id) const;
td_api::object_ptr<td_api::webPageInstantView> get_web_page_instant_view_object(WebPageId web_page_id) const;
void get_web_page_preview(td_api::object_ptr<td_api::formattedText> &&text,
td_api::object_ptr<td_api::linkPreviewOptions> &&link_preview_options,
@ -138,7 +138,11 @@ class WebPagesManager final : public Actor {
void get_web_page_instant_view_impl(WebPageId web_page_id, bool force_full, Promise<WebPageId> &&promise);
tl_object_ptr<td_api::webPageInstantView> get_web_page_instant_view_object(
td_api::object_ptr<td_api::LinkPreviewType> get_link_preview_type_object(const WebPage *web_page,
bool force_small_media,
bool force_large_media) const;
td_api::object_ptr<td_api::webPageInstantView> get_web_page_instant_view_object(
WebPageId web_page_id, const WebPageInstantView *web_page_instant_view, Slice web_page_url) const;
static void on_pending_web_page_timeout_callback(void *web_pages_manager_ptr, int64 web_page_id_int);