From 104727cb75c43c2cfc741c8bd812dc1f0e9a79b3 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 16 Oct 2023 17:36:45 +0300 Subject: [PATCH] Add webPage.force_*_media flags. --- td/generate/scheme/td_api.tl | 4 +++- td/telegram/MessageContent.cpp | 8 ++++++-- td/telegram/WebPagesManager.cpp | 9 +++++---- td/telegram/WebPagesManager.h | 3 ++- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 53c83387f..7209e2a6b 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2092,6 +2092,8 @@ webPageInstantView page_blocks:vector view_count:int32 version:int32 //@duration Duration of the content, in seconds //@author Author of the content //@has_large_media True, if the preview has large media and its appearance can be changed +//@force_small_media True, if shown media preview should be small +//@force_large_media True, if shown media preview should be large //@animation Preview of the content as an animation, if available; may be null //@audio Preview of the content as an audio file, if available; may be null //@document Preview of the content as a document, if available; may be null @@ -2102,7 +2104,7 @@ webPageInstantView page_blocks:vector view_count:int32 version:int32 //@story_sender_chat_id The identifier of the sender of the previewed story; 0 if none //@story_id The identifier of the previewed story; 0 if none //@instant_view_version Version of web page instant view (currently, can be 1 or 2); 0 if none -webPage url:string display_url:string type:string site_name:string title:string description:formattedText photo:photo embed_url:string embed_type:string embed_width:int32 embed_height:int32 duration:int32 author:string has_large_media:Bool animation:animation audio:audio document:document sticker:sticker video:video video_note:videoNote voice_note:voiceNote story_sender_chat_id:int53 story_id:int32 instant_view_version:int32 = WebPage; +webPage url:string display_url:string type:string site_name:string title:string description:formattedText photo:photo embed_url:string embed_type:string embed_width:int32 embed_height:int32 duration:int32 author:string has_large_media:Bool force_small_media:Bool force_large_media:Bool animation:animation audio:audio document:document sticker:sticker video:video video_note:videoNote voice_note:voiceNote story_sender_chat_id:int53 story_id:int32 instant_view_version:int32 = WebPage; //@description Contains information about a country diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 1faf1802d..ff4a0b3bc 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -3872,12 +3872,15 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo need_update = true; } if (old_->web_page_id != new_->web_page_id || old_->force_small_media != new_->force_small_media || - old_->force_large_media != new_->force_large_media || old_->is_manual != new_->is_manual) { + old_->force_large_media != new_->force_large_media) { LOG(INFO) << "Old: " << old_->web_page_id << ", new: " << new_->web_page_id; is_content_changed = true; need_update |= td->web_pages_manager_->have_web_page(old_->web_page_id) || td->web_pages_manager_->have_web_page(new_->web_page_id); } + if (old_->is_manual != new_->is_manual) { + need_update = true; + } break; } case MessageContentType::Animation: { @@ -6087,7 +6090,8 @@ tl_object_ptr get_message_content_object(const MessageCo } return make_tl_object( get_formatted_text_object(m->text, skip_bot_commands, max_media_timestamp), - td->web_pages_manager_->get_web_page_object(m->web_page_id), disable_web_page_preview || m->is_manual); + td->web_pages_manager_->get_web_page_object(m->web_page_id, m->force_small_media, m->force_large_media), + disable_web_page_preview || m->is_manual); } case MessageContentType::Unsupported: return make_tl_object(); diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index 79530a68f..54df6b181 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -846,7 +846,7 @@ void WebPagesManager::on_get_web_page_preview_success(const string &url, WebPage on_get_web_page_by_url(url, web_page_id, true); } - promise.set_value(get_web_page_object(web_page_id)); + promise.set_value(get_web_page_object(web_page_id, false, false)); } void WebPagesManager::get_web_page_preview(td_api::object_ptr &&text, @@ -863,7 +863,7 @@ void WebPagesManager::get_web_page_preview(td_api::object_ptrcreate_handler(std::move(promise)) ->send(formatted_text.text, @@ -1207,7 +1207,8 @@ bool WebPagesManager::have_web_page(WebPageId web_page_id) const { return get_web_page(web_page_id) != nullptr; } -tl_object_ptr WebPagesManager::get_web_page_object(WebPageId web_page_id) const { +tl_object_ptr WebPagesManager::get_web_page_object(WebPageId web_page_id, bool force_small_media, + bool force_large_media) const { if (!web_page_id.is_valid()) { return nullptr; } @@ -1311,7 +1312,7 @@ tl_object_ptr WebPagesManager::get_web_page_object(WebPageId we get_formatted_text_object(description, true, duration == 0 ? std::numeric_limits::max() : duration), get_photo_object(td_->file_manager_.get(), web_page->photo_), web_page->embed_url_, web_page->embed_type_, web_page->embed_dimensions_.width, web_page->embed_dimensions_.height, web_page->duration_, web_page->author_, - web_page->has_large_media_, + web_page->has_large_media_, force_small_media, web_page->has_large_media_ && force_large_media, web_page->document_.type == Document::Type::Animation ? td_->animations_manager_->get_animation_object(web_page->document_.file_id) : nullptr, diff --git a/td/telegram/WebPagesManager.h b/td/telegram/WebPagesManager.h index 357be3db0..d64a8e1f4 100644 --- a/td/telegram/WebPagesManager.h +++ b/td/telegram/WebPagesManager.h @@ -60,7 +60,8 @@ class WebPagesManager final : public Actor { bool have_web_page_force(WebPageId web_page_id); - tl_object_ptr get_web_page_object(WebPageId web_page_id) const; + tl_object_ptr get_web_page_object(WebPageId web_page_id, bool force_small_media, + bool force_large_media) const; tl_object_ptr get_web_page_instant_view_object(WebPageId web_page_id) const;