Add linkPreviewTypeAudio/linkPreviewTypeVideo.

This commit is contained in:
levlam 2024-07-04 13:57:15 +03:00
parent baec4850ae
commit f2a855901a
2 changed files with 45 additions and 3 deletions

View File

@ -2553,6 +2553,14 @@ webPageInstantView page_blocks:vector<PageBlock> view_count:int32 version:int32
//@class LinkPreviewType @description Describes type of a link preview
//@description The link is a link to an audio
//@url URL of the audio; may be empty if none
//@mime_type MIME type of the audio file
//@audio Description of the audio; may be null if unknown
//@duration Duration of the audio, in seconds; 0 if unknown
//@author Author of the audio
linkPreviewTypeAudio url:string mime_type:string audio:audio duration:int32 author:string = LinkPreviewType;
//@description The link is a link to a background. Link preview title and description are available only for filled backgrounds @document Document with the background; may be null for filled backgrounds
linkPreviewTypeBackground document:document = LinkPreviewType;
@ -2603,6 +2611,16 @@ linkPreviewTypeTheme documents:vector<document> = LinkPreviewType;
//@description The link is a link to a user @photo Photo of the user; may be null if none @is_bot True, if the user is a bot
linkPreviewTypeUser photo:chatPhoto is_bot:Bool = LinkPreviewType;
//@description The link is a link to a video
//@url URL of the video; may be empty if none
//@mime_type MIME type of the video file
//@video Description of the video; may be null if unknown
//@width Expected width of the preview
//@height Expected height of the preview
//@duration Duration of the video, in seconds; 0 if unknown
//@author Author of the video
linkPreviewTypeVideo url:string mime_type:string video:video width:int32 height:int32 duration:int32 author:string = LinkPreviewType;
//@description The link is a link to a video chat
//@photo Photo of the chat with the video chat; may be null if none
//@is_live_stream True, if the video chat is expected to be a live stream in a channel or a broadcast group

View File

@ -1436,10 +1436,34 @@ td_api::object_ptr<td_api::LinkPreviewType> WebPagesManager::get_link_preview_ty
web_page->embed_url_, web_page->duration_, web_page->author_, web_page->embed_dimensions_.width,
web_page->embed_dimensions_.height);
}
LOG(ERROR) << "Have type = " << web_page->type_ << " for embedded " << web_page->url_;
return td_api::make_object<td_api::linkPreviewTypeOther>(web_page->type_);
} else {
// ordinary audio/video
if (web_page->type_ == "audio") {
auto audio = web_page->document_.type == Document::Type::Audio
? td_->audios_manager_->get_audio_object(web_page->document_.file_id)
: nullptr;
if (audio != nullptr || !web_page->embed_url_.empty()) {
return td_api::make_object<td_api::linkPreviewTypeAudio>(
web_page->embed_url_, web_page->embed_type_, std::move(audio), web_page->duration_, web_page->author_);
} else {
return td_api::make_object<td_api::linkPreviewTypeOther>(web_page->type_);
}
}
if (web_page->type_ == "video") {
auto video = web_page->document_.type == Document::Type::Video
? td_->videos_manager_->get_video_object(web_page->document_.file_id)
: nullptr;
if (video != nullptr || !web_page->embed_url_.empty()) {
return td_api::make_object<td_api::linkPreviewTypeVideo>(
web_page->embed_url_, web_page->embed_type_, std::move(video), web_page->embed_dimensions_.width,
web_page->embed_dimensions_.height, web_page->duration_, web_page->author_);
} else {
return td_api::make_object<td_api::linkPreviewTypeOther>(web_page->type_);
}
}
}
// ordinary audio/video
LOG(ERROR) << "Have type = " << web_page->type_ << " for embedded " << web_page->url_;
return td_api::make_object<td_api::linkPreviewTypeOther>(web_page->type_);
}
// TODO LOG(ERROR) << "Receive link preview of unsupported type " << web_page->type_;
return td_api::make_object<td_api::linkPreviewTypeOther>(web_page->type_);