From 46d188e35c48b0caa58b3ae8ca20dfbb37b28361 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 1 Nov 2023 21:55:12 +0300 Subject: [PATCH] Return full link_preview_options in messageText. --- td/generate/scheme/td_api.tl | 23 ++++++++++++----------- td/telegram/MessageContent.cpp | 13 ++++++++++--- td/telegram/MessageContent.h | 3 ++- td/telegram/MessagesManager.cpp | 16 +++++++++------- td/telegram/RepliedMessageInfo.cpp | 2 +- td/telegram/SponsoredMessageManager.cpp | 2 +- 6 files changed, 35 insertions(+), 24 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index ec07f07d7..45bfbfd21 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1839,6 +1839,15 @@ forumTopic info:forumTopicInfo last_message:message is_pinned:Bool unread_count: forumTopics total_count:int32 topics:vector next_offset_date:int32 next_offset_message_id:int53 next_offset_message_thread_id:int53 = ForumTopics; +//@description Options to be used for generation of a link preview +//@is_disabled True, if link preview must be disabled +//@url URL to use for link preview. If empty, then the first URL found in the message text will be used +//@force_small_media True, if shown media preview must be small; ignored in secret chats or if the URL isn't explicitly specified +//@force_large_media True, if shown media preview must be large; ignored in secret chats or if the URL isn't explicitly specified +//@show_above_text True, if link preview must be shown above message text; otherwise, the link preview will be shown below the message text; ignored in secret chats +linkPreviewOptions is_disabled:Bool url:string force_small_media:Bool force_large_media:Bool show_above_text:Bool = LinkPreviewOptions; + + //@class RichText @description Describes a text object inside an instant-view web page //@description A plain text @text Text @@ -2617,9 +2626,9 @@ inputPassportElementError type:PassportElementType message:string source:InputPa //@description A text message //@text Text of the message -//@web_page A preview of the web page that's mentioned in the text; may be null -//@web_page_url URL manually chosen for link preview in the message -messageText text:formattedText web_page:webPage web_page_url:string = MessageContent; +//@web_page A link preview attached to the message; may be null +//@link_preview_options Options which was used for generation of the link preview; may be null if default options were used +messageText text:formattedText web_page:webPage link_preview_options:linkPreviewOptions = MessageContent; //@description An animation message (GIF-style). //@animation The animation description @@ -2989,14 +2998,6 @@ messageSendOptions disable_notification:Bool from_background:Bool protect_conten //@new_caption New message caption; pass null to copy message without caption. Ignored if replace_caption is false messageCopyOptions send_copy:Bool replace_caption:Bool new_caption:formattedText = MessageCopyOptions; -//@description Options to be used for generation of a link preview -//@is_disabled True, if link preview must be disabled -//@url URL to use for link preview. If empty, then the first URL found in the message text will be used -//@force_small_media True, if shown media preview must be small; ignored in secret chats or if the URL isn't explicitly specified -//@force_large_media True, if shown media preview must be large; ignored in secret chats or if the URL isn't explicitly specified -//@show_above_text True, if link preview must be shown above message text; otherwise, the link preview will be shown below the message text; ignored in secret chats -linkPreviewOptions is_disabled:Bool url:string force_small_media:Bool force_large_media:Bool show_above_text:Bool = LinkPreviewOptions; - //@class InputMessageContent @description The content of a message to send diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index b887adbc5..8d6515b67 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -3971,7 +3971,7 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo const auto *new_ = static_cast(new_content); auto get_content_object = [td, dialog_id](const MessageContent *content) { return to_string(get_message_content_object(content, td, dialog_id, -1, false, false, - std::numeric_limits::max(), false)); + std::numeric_limits::max(), false, false)); }; if (old_->text.text != new_->text.text) { if (need_message_changed_warning && need_message_text_changed_warning(old_, new_)) { @@ -6245,7 +6245,8 @@ unique_ptr get_action_message_content(Td *td, tl_object_ptr get_message_content_object(const MessageContent *content, Td *td, DialogId dialog_id, int32 message_date, bool is_content_secret, bool skip_bot_commands, - int32 max_media_timestamp, bool invert_media) { + int32 max_media_timestamp, bool invert_media, + bool disable_web_page_preview) { CHECK(content != nullptr); switch (content->get_type()) { case MessageContentType::Animation: { @@ -6326,9 +6327,15 @@ tl_object_ptr get_message_content_object(const MessageCo if (web_page != nullptr && !web_page->skip_confirmation_ && is_visible_url(m->text, web_page->url_)) { web_page->skip_confirmation_ = true; } + td_api::object_ptr link_preview_options; + if (disable_web_page_preview || !m->web_page_url.empty() || m->force_small_media || m->force_large_media || + invert_media) { + link_preview_options = td_api::make_object( + disable_web_page_preview, m->web_page_url, m->force_small_media, m->force_large_media, invert_media); + } return make_tl_object( get_formatted_text_object(m->text, skip_bot_commands, max_media_timestamp), std::move(web_page), - m->web_page_url); + std::move(link_preview_options)); } case MessageContentType::Unsupported: return make_tl_object(); diff --git a/td/telegram/MessageContent.h b/td/telegram/MessageContent.h index 5a9107d2b..fb150ff74 100644 --- a/td/telegram/MessageContent.h +++ b/td/telegram/MessageContent.h @@ -234,7 +234,8 @@ unique_ptr get_action_message_content(Td *td, tl_object_ptr get_message_content_object(const MessageContent *content, Td *td, DialogId dialog_id, int32 message_date, bool is_content_secret, bool skip_bot_commands, - int32 max_media_timestamp, bool invert_media); + int32 max_media_timestamp, bool invert_media, + bool disable_web_page_preview); FormattedText *get_message_content_text_mutable(MessageContent *content); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 59d5d6805..eb8b88e4a 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -6597,10 +6597,11 @@ void MessagesManager::on_update_service_notification(tl_object_ptrget_type()); if (update->popup_) { - send_closure(G()->td(), &Td::send_update, - td_api::make_object( - update->type_, get_message_content_object(content.get(), td_, owner_dialog_id, date, - is_content_secret, true, -1, update->invert_media_))); + send_closure( + G()->td(), &Td::send_update, + td_api::make_object( + update->type_, get_message_content_object(content.get(), td_, owner_dialog_id, date, is_content_secret, + true, -1, update->invert_media_, disable_web_page_preview))); } if (has_date && is_user) { Dialog *d = get_service_notifications_dialog(); @@ -24016,7 +24017,7 @@ td_api::object_ptr MessagesManager::get_message_message_ auto live_location_date = m->is_failed_to_send ? 0 : m->date; return get_message_content_object(m->content.get(), td_, dialog_id, live_location_date, m->is_content_secret, need_skip_bot_commands(dialog_id, m), get_message_max_media_timestamp(m), - m->invert_media); + m->invert_media, m->disable_web_page_preview); } td_api::object_ptr MessagesManager::get_dialog_event_log_message_object( @@ -24039,8 +24040,9 @@ td_api::object_ptr MessagesManager::get_dialog_event_log_messag auto via_bot_user_id = td_->contacts_manager_->get_user_id_object(m->via_bot_user_id, "via_bot_user_id"); auto edit_date = m->hide_edit_date ? 0 : m->edit_date; auto reply_markup = get_reply_markup_object(td_->contacts_manager_.get(), m->reply_markup); - auto content = get_message_content_object(m->content.get(), td_, dialog_id, 0, false, true, - get_message_own_max_media_timestamp(m), m->invert_media); + auto content = + get_message_content_object(m->content.get(), td_, dialog_id, 0, false, true, + get_message_own_max_media_timestamp(m), m->invert_media, m->disable_web_page_preview); return td_api::make_object( m->message_id.get(), std::move(sender), get_chat_id_object(dialog_id, "get_dialog_event_log_message_object"), nullptr, nullptr, m->is_outgoing, false, false, false, false, can_be_saved, false, false, false, false, false, diff --git a/td/telegram/RepliedMessageInfo.cpp b/td/telegram/RepliedMessageInfo.cpp index be4a1a20f..d0bd6c798 100644 --- a/td/telegram/RepliedMessageInfo.cpp +++ b/td/telegram/RepliedMessageInfo.cpp @@ -339,7 +339,7 @@ td_api::object_ptr RepliedMessageInfo::get_messag td_api::object_ptr content; if (content_ != nullptr) { - content = get_message_content_object(content_.get(), td, dialog_id, 0, false, true, -1, false); + content = get_message_content_object(content_.get(), td, dialog_id, 0, false, true, -1, false, false); if (content->get_id() == td_api::messageUnsupported::ID || (content->get_id() == td_api::messageText::ID && static_cast(content.get())->web_page_ == nullptr)) { diff --git a/td/telegram/SponsoredMessageManager.cpp b/td/telegram/SponsoredMessageManager.cpp index ea6f54e7a..3d278a90f 100644 --- a/td/telegram/SponsoredMessageManager.cpp +++ b/td/telegram/SponsoredMessageManager.cpp @@ -291,7 +291,7 @@ td_api::object_ptr SponsoredMessageManager::get_sponso } return td_api::make_object( sponsored_message.local_id, sponsored_message.is_recommended, - get_message_content_object(sponsored_message.content.get(), td_, dialog_id, 0, false, true, -1, false), + get_message_content_object(sponsored_message.content.get(), td_, dialog_id, 0, false, true, -1, false, false), std::move(sponsor), sponsored_message.additional_info); }