Ignore force_*_media if url isn't specified exlicitly.

This commit is contained in:
levlam 2023-10-16 23:06:48 +03:00
parent cdedb9ee1f
commit b0df339750
3 changed files with 15 additions and 14 deletions

View File

@ -2966,8 +2966,8 @@ messageCopyOptions send_copy:Bool replace_caption:Bool new_caption:formattedText
//@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
//@force_large_media True, if shown media preview must be large; ignored in secret chats
//@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
linkPreviewOptions is_disabled:Bool url:string force_small_media:Bool force_large_media:Bool = LinkPreviewOptions;

View File

@ -44,13 +44,17 @@ Result<InputMessageText> process_input_message_text(const Td *td, DialogId dialo
if (!clean_input_string(web_page_url)) {
return Status::Error(400, "Link preview URL must be encoded in UTF-8");
}
if (web_page_url.empty()) {
force_small_media = false;
force_large_media = false;
}
}
return InputMessageText{std::move(text), std::move(web_page_url), disable_web_page_preview,
force_small_media, force_large_media, input_message_text->clear_draft_};
}
telegram_api::object_ptr<telegram_api::InputMedia> InputMessageText::get_input_media_web_page() const {
if (web_page_url.empty() && !force_small_media && !force_large_media) {
if (web_page_url.empty()) {
return nullptr;
}
int32 flags = 0;
@ -70,14 +74,12 @@ telegram_api::object_ptr<telegram_api::InputMedia> InputMessageText::get_input_m
// used only for draft
td_api::object_ptr<td_api::inputMessageText> InputMessageText::get_input_message_text_object() const {
td_api::object_ptr<td_api::linkPreviewOptions> options;
if (!web_page_url.empty() || disable_web_page_preview ||
force_small_media || force_large_media) {
options = td_api::make_object<td_api::linkPreviewOptions>(
disable_web_page_preview, web_page_url,
force_small_media, force_large_media);
if (!web_page_url.empty() || disable_web_page_preview || force_small_media || force_large_media) {
options = td_api::make_object<td_api::linkPreviewOptions>(disable_web_page_preview, web_page_url, force_small_media,
force_large_media);
}
return td_api::make_object<td_api::inputMessageText>(get_formatted_text_object(text, false, -1),
std::move(options), clear_draft);
return td_api::make_object<td_api::inputMessageText>(get_formatted_text_object(text, false, -1), std::move(options),
clear_draft);
}
} // namespace td

View File

@ -3017,7 +3017,7 @@ tl_object_ptr<telegram_api::InputMedia> get_message_content_input_media_web_page
return nullptr;
}
auto *text = static_cast<const MessageText *>(content);
if (text->web_page_url.empty() && !text->force_small_media && !text->force_large_media) {
if (text->web_page_url.empty()) {
return nullptr;
}
int32 flags = 0;
@ -3030,9 +3030,8 @@ tl_object_ptr<telegram_api::InputMedia> get_message_content_input_media_web_page
if (!text->text.text.empty()) {
flags |= telegram_api::inputMediaWebPage::OPTIONAL_MASK;
}
return telegram_api::make_object<telegram_api::inputMediaWebPage>(
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/,
text->web_page_url.empty() ? td->web_pages_manager_->get_web_page_url(text->web_page_id) : text->web_page_url);
return telegram_api::make_object<telegram_api::inputMediaWebPage>(flags, false /*ignored*/, false /*ignored*/,
false /*ignored*/, text->web_page_url);
}
void delete_message_content_thumbnail(MessageContent *content, Td *td) {