Add linkPreview.show_media_above_description.

This commit is contained in:
levlam 2024-07-11 14:16:19 +03:00
parent 2f3efdaa73
commit 008962a7e9
2 changed files with 20 additions and 5 deletions

View File

@ -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

View File

@ -1820,12 +1820,26 @@ td_api::object_ptr<td_api::linkPreview> 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<td_api::linkPreview>(
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<int32>::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<int32>::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<td_api::webPageInstantView> WebPagesManager::get_web_page_instant_view_object(