Return full link_preview_options in messageText.

This commit is contained in:
levlam 2023-11-01 21:55:12 +03:00
parent 6f4bb7d099
commit 46d188e35c
6 changed files with 35 additions and 24 deletions

View File

@ -1839,6 +1839,15 @@ forumTopic info:forumTopicInfo last_message:message is_pinned:Bool unread_count:
forumTopics total_count:int32 topics:vector<forumTopic> 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

View File

@ -3971,7 +3971,7 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
const auto *new_ = static_cast<const MessageText *>(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<int32>::max(), false));
std::numeric_limits<int32>::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<MessageContent> get_action_message_content(Td *td, tl_object_ptr<tele
tl_object_ptr<td_api::MessageContent> 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<td_api::MessageContent> 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<td_api::linkPreviewOptions> 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<td_api::linkPreviewOptions>(
disable_web_page_preview, m->web_page_url, m->force_small_media, m->force_large_media, invert_media);
}
return make_tl_object<td_api::messageText>(
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<td_api::messageUnsupported>();

View File

@ -234,7 +234,8 @@ unique_ptr<MessageContent> get_action_message_content(Td *td, tl_object_ptr<tele
tl_object_ptr<td_api::MessageContent> 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);

View File

@ -6597,10 +6597,11 @@ void MessagesManager::on_update_service_notification(tl_object_ptr<telegram_api:
bool is_content_secret = is_secret_message_content(ttl, content->get_type());
if (update->popup_) {
send_closure(G()->td(), &Td::send_update,
td_api::make_object<td_api::updateServiceNotification>(
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<td_api::updateServiceNotification>(
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<td_api::MessageContent> 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<td_api::message> MessagesManager::get_dialog_event_log_message_object(
@ -24039,8 +24040,9 @@ td_api::object_ptr<td_api::message> 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<td_api::message>(
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,

View File

@ -339,7 +339,7 @@ td_api::object_ptr<td_api::messageReplyToMessage> RepliedMessageInfo::get_messag
td_api::object_ptr<td_api::MessageContent> 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<const td_api::messageText *>(content.get())->web_page_ == nullptr)) {

View File

@ -291,7 +291,7 @@ td_api::object_ptr<td_api::sponsoredMessage> SponsoredMessageManager::get_sponso
}
return td_api::make_object<td_api::sponsoredMessage>(
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);
}