From 008962a7e9c9df238051e705b314f6d9a058dd8e Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 11 Jul 2024 14:16:19 +0300 Subject: [PATCH] Add linkPreview.show_media_above_description. --- td/generate/scheme/td_api.tl | 3 ++- td/telegram/WebPagesManager.cpp | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 0aa51b297..40f4c9f1f 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2686,10 +2686,11 @@ linkPreviewTypeWebApp photo:photo = LinkPreviewType; //@type Type of the link preview //@has_large_media True, if size of media in the preview can be changed //@show_large_media True, if large media preview must be shown; otherwise, the media preview must be shown small and only the first frame must be shown for videos +//@show_media_above_description True, if media must be shown above link preview description; otherwise, the media must be shown below the description //@skip_confirmation True, if there is no need to show an ordinary open URL confirmation, when opening the URL from the preview, because the URL is shown in the message text in clear //@show_above_text True, if the link preview must be shown above message text; otherwise, the link preview must be shown below the message text //@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 site_name:string title:string description:formattedText type:LinkPreviewType has_large_media:Bool show_large_media:Bool skip_confirmation:Bool show_above_text:Bool instant_view_version:int32 = LinkPreview; +linkPreview url:string display_url:string site_name:string title:string description:formattedText type:LinkPreviewType has_large_media:Bool show_large_media:Bool show_media_above_description:Bool skip_confirmation:Bool show_above_text:Bool instant_view_version:int32 = LinkPreview; //@description Contains information about a country diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index 6bd3e26bc..fed1b4ce3 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -1820,12 +1820,26 @@ td_api::object_ptr WebPagesManager::get_link_preview_object } return false; }(); + auto link_preview_type = get_link_preview_type_object(web_page); + bool show_media_above_description = false; + if (show_large_media) { + auto type_id = link_preview_type->get_id(); + if (!web_page->embed_url_.empty() || type_id == td_api::linkPreviewTypeStory::ID) { + show_media_above_description = true; + } else if (type_id == td_api::linkPreviewTypeAlbum::ID || + (type_id == td_api::linkPreviewTypePhoto::ID && instant_view_version > 0)) { + for (auto &photo_size : web_page->photo_.photos) { + if (photo_size.dimensions.width >= 256) { + show_media_above_description = true; + } + } + } + } return td_api::make_object( web_page->url_, web_page->display_url_, web_page->site_name_, web_page->title_, - get_formatted_text_object(td_->user_manager_.get(), description, true, - duration == 0 ? std::numeric_limits::max() : duration), - get_link_preview_type_object(web_page), web_page->has_large_media_, show_large_media, skip_confirmation, - invert_media, instant_view_version); + get_formatted_text_object(td_->user_manager_.get(), description, true, duration == 0 ? std::numeric_limits::max() : duration), + std::move(link_preview_type), web_page->has_large_media_, show_large_media, show_media_above_description, + skip_confirmation, invert_media, instant_view_version); } td_api::object_ptr WebPagesManager::get_web_page_instant_view_object(