Support embedded animations.

This commit is contained in:
levlam 2024-07-29 15:37:21 +03:00
parent 65057a9802
commit fa4c3082b1
2 changed files with 32 additions and 1 deletions

View File

@ -2609,6 +2609,15 @@ linkPreviewTypeChat type:InviteLinkChatType photo:chatPhoto creates_join_request
//@description The link is a link to a general file @document The document description @author Author of the document
linkPreviewTypeDocument document:document author:string = LinkPreviewType;
//@description The link is a link to an animation player
//@url URL of the external animation player
//@thumbnail Thumbnail of the animation; may be null if unknown
//@duration Duration of the animation, in seconds
//@author Author of the animation
//@width Expected width of the embedded player
//@height Expected height of the embedded player
linkPreviewTypeEmbeddedAnimationPlayer url:string thumbnail:photo duration:int32 author:string width:int32 height:int32 = LinkPreviewType;
//@description The link is a link to an audio player
//@url URL of the external audio player
//@thumbnail Thumbnail of the audio; may be null if unknown

View File

@ -1545,13 +1545,18 @@ td_api::object_ptr<td_api::LinkPreviewType> WebPagesManager::get_link_preview_ty
web_page->embed_url_, get_photo_object(td_->file_manager_.get(), web_page->photo_), web_page->duration_,
web_page->author_, web_page->embed_dimensions_.width, web_page->embed_dimensions_.height);
}
if (web_page->type_ == "gif") {
return td_api::make_object<td_api::linkPreviewTypeEmbeddedAnimationPlayer>(
web_page->embed_url_, get_photo_object(td_->file_manager_.get(), web_page->photo_), web_page->duration_,
web_page->author_, web_page->embed_dimensions_.width, web_page->embed_dimensions_.height);
}
if (web_page->type_ == "video") {
return td_api::make_object<td_api::linkPreviewTypeEmbeddedVideoPlayer>(
web_page->embed_url_, get_photo_object(td_->file_manager_.get(), web_page->photo_), web_page->duration_,
web_page->author_, web_page->embed_dimensions_.width, web_page->embed_dimensions_.height);
}
} else {
// ordinary audio/video
// ordinary animation/audio/video
if (web_page->type_ == "audio") {
LOG_IF(ERROR,
web_page->document_.type != Document::Type::Unknown && web_page->document_.type != Document::Type::Audio)
@ -1570,6 +1575,23 @@ td_api::object_ptr<td_api::LinkPreviewType> WebPagesManager::get_link_preview_ty
return td_api::make_object<td_api::linkPreviewTypeUnsupported>();
}
}
if (web_page->type_ == "gif") {
LOG_IF(ERROR, web_page->document_.type != Document::Type::Unknown &&
web_page->document_.type != Document::Type::Animation)
<< "Receive wrong document for " << web_page->url_;
auto animation = web_page->document_.type == Document::Type::Animation
? td_->animations_manager_->get_animation_object(web_page->document_.file_id)
: nullptr;
if (animation != nullptr) {
return td_api::make_object<td_api::linkPreviewTypeAnimation>(std::move(animation), web_page->author_);
} else {
if (!web_page->photo_.is_empty()) {
return td_api::make_object<td_api::linkPreviewTypePhoto>(
get_photo_object(td_->file_manager_.get(), web_page->photo_), web_page->author_);
}
return td_api::make_object<td_api::linkPreviewTypeUnsupported>();
}
}
if (web_page->type_ == "video") {
LOG_IF(ERROR,
web_page->document_.type != Document::Type::Unknown && web_page->document_.type != Document::Type::Video)