From f2a855901a203f394fb63ac8514095b313286029 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 4 Jul 2024 13:57:15 +0300 Subject: [PATCH] Add linkPreviewTypeAudio/linkPreviewTypeVideo. --- td/generate/scheme/td_api.tl | 18 ++++++++++++++++++ td/telegram/WebPagesManager.cpp | 30 +++++++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 2f187c45e..a53533648 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2553,6 +2553,14 @@ webPageInstantView page_blocks:vector 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 = 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 diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index 8c27eec89..c5cddcb53 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -1436,10 +1436,34 @@ td_api::object_ptr 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(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( + web_page->embed_url_, web_page->embed_type_, std::move(audio), web_page->duration_, web_page->author_); + } else { + return td_api::make_object(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( + 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(web_page->type_); + } + } } - // ordinary audio/video + LOG(ERROR) << "Have type = " << web_page->type_ << " for embedded " << web_page->url_; + return td_api::make_object(web_page->type_); } // TODO LOG(ERROR) << "Receive link preview of unsupported type " << web_page->type_; return td_api::make_object(web_page->type_);