Support sending messages with caption above media.

This commit is contained in:
levlam 2024-05-15 18:04:42 +03:00
parent 31b348e108
commit bbf45047d0
5 changed files with 87 additions and 43 deletions

View File

@ -3421,8 +3421,9 @@ inputMessageText text:formattedText link_preview_options:linkPreviewOptions clea
//@width Width of the animation; may be replaced by the server
//@height Height of the animation; may be replaced by the server
//@caption Animation caption; pass null to use an empty caption; 0-getOption("message_caption_length_max") characters
//@show_caption_above_media True, if caption must be shown above the animation; otherwise caption must be shown below the animation; not supported in secret chats
//@has_spoiler True, if the animation preview must be covered by a spoiler animation; not supported in secret chats
inputMessageAnimation animation:InputFile thumbnail:inputThumbnail added_sticker_file_ids:vector<int32> duration:int32 width:int32 height:int32 caption:formattedText has_spoiler:Bool = InputMessageContent;
inputMessageAnimation animation:InputFile thumbnail:inputThumbnail added_sticker_file_ids:vector<int32> duration:int32 width:int32 height:int32 caption:formattedText show_caption_above_media:Bool has_spoiler:Bool = InputMessageContent;
//@description An audio message
//@audio Audio file to be sent
@ -3447,9 +3448,10 @@ inputMessageDocument document:InputFile thumbnail:inputThumbnail disable_content
//@width Photo width
//@height Photo height
//@caption Photo caption; pass null to use an empty caption; 0-getOption("message_caption_length_max") characters
//@show_caption_above_media True, if caption must be shown above the photo; otherwise caption must be shown below the photo; not supported in secret chats
//@self_destruct_type Photo self-destruct type; pass null if none; private chats only
//@has_spoiler True, if the photo preview must be covered by a spoiler animation; not supported in secret chats
inputMessagePhoto photo:InputFile thumbnail:inputThumbnail added_sticker_file_ids:vector<int32> width:int32 height:int32 caption:formattedText self_destruct_type:MessageSelfDestructType has_spoiler:Bool = InputMessageContent;
inputMessagePhoto photo:InputFile thumbnail:inputThumbnail added_sticker_file_ids:vector<int32> width:int32 height:int32 caption:formattedText show_caption_above_media:Bool self_destruct_type:MessageSelfDestructType has_spoiler:Bool = InputMessageContent;
//@description A sticker message
//@sticker Sticker to be sent
@ -3468,9 +3470,10 @@ inputMessageSticker sticker:InputFile thumbnail:inputThumbnail width:int32 heigh
//@height Video height
//@supports_streaming True, if the video is supposed to be streamed
//@caption Video caption; pass null to use an empty caption; 0-getOption("message_caption_length_max") characters
//@show_caption_above_media True, if caption must be shown above the video; otherwise caption must be shown below the video; not supported in secret chats
//@self_destruct_type Video self-destruct type; pass null if none; private chats only
//@has_spoiler True, if the video preview must be covered by a spoiler animation; not supported in secret chats
inputMessageVideo video:InputFile thumbnail:inputThumbnail added_sticker_file_ids:vector<int32> duration:int32 width:int32 height:int32 supports_streaming:Bool caption:formattedText self_destruct_type:MessageSelfDestructType has_spoiler:Bool = InputMessageContent;
inputMessageVideo video:InputFile thumbnail:inputThumbnail added_sticker_file_ids:vector<int32> duration:int32 width:int32 height:int32 supports_streaming:Bool caption:formattedText show_caption_above_media:Bool self_destruct_type:MessageSelfDestructType has_spoiler:Bool = InputMessageContent;
//@description A video note message
//@video_note Video note to be sent

View File

@ -463,6 +463,9 @@ Result<tl_object_ptr<telegram_api::InputBotInlineMessage>> InlineQueriesManager:
if (!entities.empty()) {
flags |= telegram_api::inputBotInlineMessageMediaAuto::ENTITIES_MASK;
}
if (extract_input_invert_media(input_message_content)) {
flags |= telegram_api::inputBotInlineMessageMediaAuto::INVERT_MEDIA_MASK;
}
return make_tl_object<telegram_api::inputBotInlineMessageMediaAuto>(
flags, false /*ignored*/, caption.text, std::move(entities), std::move(input_reply_markup));
}

View File

@ -2627,6 +2627,25 @@ td_api::object_ptr<td_api::formattedText> extract_input_caption(
}
}
bool extract_input_invert_media(const td_api::object_ptr<td_api::InputMessageContent> &input_message_content) {
switch (input_message_content->get_id()) {
case td_api::inputMessageAnimation::ID: {
auto input_animation = static_cast<const td_api::inputMessageAnimation *>(input_message_content.get());
return input_animation->show_caption_above_media_;
}
case td_api::inputMessagePhoto::ID: {
auto input_photo = static_cast<const td_api::inputMessagePhoto *>(input_message_content.get());
return input_photo->show_caption_above_media_;
}
case td_api::inputMessageVideo::ID: {
auto input_video = static_cast<const td_api::inputMessageVideo *>(input_message_content.get());
return input_video->show_caption_above_media_;
}
default:
return false;
}
}
static Result<InputMessageContent> create_input_message_content(
DialogId dialog_id, tl_object_ptr<td_api::InputMessageContent> &&input_message_content, Td *td,
FormattedText caption, FileId file_id, PhotoSize thumbnail, vector<FileId> sticker_file_ids, bool is_premium) {
@ -2683,6 +2702,8 @@ static Result<InputMessageContent> create_input_message_content(
case td_api::inputMessageAnimation::ID: {
auto input_animation = static_cast<td_api::inputMessageAnimation *>(input_message_content.get());
invert_media = input_animation->show_caption_above_media_ && !is_secret;
bool has_stickers = !sticker_file_ids.empty();
td->animations_manager_->create_animation(
file_id, string(), thumbnail, AnimationSize(), has_stickers, std::move(sticker_file_ids),
@ -2727,6 +2748,7 @@ static Result<InputMessageContent> create_input_message_content(
case td_api::inputMessagePhoto::ID: {
auto input_photo = static_cast<td_api::inputMessagePhoto *>(input_message_content.get());
invert_media = input_photo->show_caption_above_media_ && !is_secret;
self_destruct_type = std::move(input_photo->self_destruct_type_);
TRY_RESULT(photo, create_photo(td->file_manager_.get(), file_id, std::move(thumbnail), input_photo->width_,
@ -2751,6 +2773,7 @@ static Result<InputMessageContent> create_input_message_content(
case td_api::inputMessageVideo::ID: {
auto input_video = static_cast<td_api::inputMessageVideo *>(input_message_content.get());
invert_media = input_video->show_caption_above_media_ && !is_secret;
self_destruct_type = std::move(input_video->self_destruct_type_);
bool has_stickers = !sticker_file_ids.empty();

View File

@ -113,6 +113,8 @@ unique_ptr<MessageContent> create_chat_set_ttl_message_content(int32 ttl, UserId
td_api::object_ptr<td_api::formattedText> extract_input_caption(
td_api::object_ptr<td_api::InputMessageContent> &input_message_content);
bool extract_input_invert_media(const td_api::object_ptr<td_api::InputMessageContent> &input_message_content);
Result<InputMessageContent> get_input_message_content(
DialogId dialog_id, tl_object_ptr<td_api::InputMessageContent> &&input_message_content, Td *td, bool is_premium);

View File

@ -4804,7 +4804,7 @@ class CliClient final : public Actor {
if (op[3] == 'p') {
send_message(chat_id, td_api::make_object<td_api::inputMessagePhoto>(
as_local_file("rgb.jpg"), nullptr, Auto(), 0, 0, as_caption(message),
get_message_self_destruct_type(), has_spoiler_));
show_caption_above_media_, get_message_self_destruct_type(), has_spoiler_));
} else {
send_message(chat_id, td_api::make_object<td_api::inputMessageText>(as_formatted_text(message),
get_link_preview_options(), true));
@ -4852,6 +4852,8 @@ class CliClient final : public Actor {
} else if (op == "slpo") {
get_args(args, link_preview_is_disabled_, link_preview_url_, link_preview_force_small_media_,
link_preview_force_large_media_, link_preview_show_above_text_);
} else if (op == "sscam") {
get_args(args, show_caption_above_media_);
} else if (op == "ssmt") {
saved_messages_topic_id_ = as_chat_id(args);
} else if (op == "sqrs") {
@ -4893,7 +4895,7 @@ class CliClient final : public Actor {
get_args(args, chat_id, args);
auto input_message_contents = transform(full_split(args), [this](const string &photo) {
td_api::object_ptr<td_api::InputMessageContent> content = td_api::make_object<td_api::inputMessagePhoto>(
as_input_file(photo), nullptr, Auto(), 0, 0, as_caption(""),
as_input_file(photo), nullptr, Auto(), 0, 0, as_caption(""), show_caption_above_media_,
rand_bool() ? get_message_self_destruct_type() : nullptr, has_spoiler_ && rand_bool());
return content;
});
@ -4981,7 +4983,8 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::editMessageMedia>(
chat_id, message_id, nullptr,
td_api::make_object<td_api::inputMessageAnimation>(as_input_file(animation), nullptr, vector<int32>(), 0, 0,
0, as_caption("animation"), has_spoiler_)));
0, as_caption("animation"), show_caption_above_media_,
has_spoiler_)));
} else if (op == "emc") {
ChatId chat_id;
MessageId message_id;
@ -5012,8 +5015,8 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::editMessageMedia>(
chat_id, message_id, nullptr,
td_api::make_object<td_api::inputMessagePhoto>(as_input_file(photo), as_input_thumbnail(photo), Auto(), 0, 0,
as_caption(""), get_message_self_destruct_type(),
has_spoiler_)));
as_caption(""), show_caption_above_media_,
get_message_self_destruct_type(), has_spoiler_)));
} else if (op == "eqrmp") {
ShortcutId shortcut_id;
MessageId message_id;
@ -5022,7 +5025,8 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::editQuickReplyMessage>(
shortcut_id, message_id,
td_api::make_object<td_api::inputMessagePhoto>(as_input_file(photo), as_input_thumbnail(photo), Auto(), 0, 0,
as_caption(""), nullptr, has_spoiler_)));
as_caption(""), show_caption_above_media_, nullptr,
has_spoiler_)));
} else if (op == "emvt") {
ChatId chat_id;
MessageId message_id;
@ -5032,8 +5036,8 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::editMessageMedia>(
chat_id, message_id, nullptr,
td_api::make_object<td_api::inputMessageVideo>(as_input_file(video), as_input_thumbnail(thumbnail), Auto(), 1,
2, 3, true, as_caption(""), get_message_self_destruct_type(),
has_spoiler_)));
2, 3, true, as_caption(""), show_caption_above_media_,
get_message_self_destruct_type(), has_spoiler_)));
} else if (op == "emll") {
ChatId chat_id;
MessageId message_id;
@ -5221,9 +5225,9 @@ class CliClient final : public Actor {
int32 height;
string caption;
get_args(args, chat_id, animation_path, width, height, caption);
send_message(chat_id, td_api::make_object<td_api::inputMessageAnimation>(as_input_file(animation_path), nullptr,
vector<int32>(), 60, width, height,
as_caption(caption), has_spoiler_));
send_message(chat_id, td_api::make_object<td_api::inputMessageAnimation>(
as_input_file(animation_path), nullptr, vector<int32>(), 60, width, height,
as_caption(caption), show_caption_above_media_, has_spoiler_));
} else if (op == "sang") {
ChatId chat_id;
string animation_path;
@ -5231,27 +5235,28 @@ class CliClient final : public Actor {
get_args(args, chat_id, animation_path, animation_conversion);
send_message(chat_id, td_api::make_object<td_api::inputMessageAnimation>(
as_generated_file(animation_path, animation_conversion), nullptr, vector<int32>(), 60,
0, 0, as_caption(""), has_spoiler_));
0, 0, as_caption(""), show_caption_above_media_, has_spoiler_));
} else if (op == "sanid") {
ChatId chat_id;
string file_id;
get_args(args, chat_id, file_id);
send_message(chat_id,
td_api::make_object<td_api::inputMessageAnimation>(
as_input_file_id(file_id), nullptr, vector<int32>(), 0, 0, 0, as_caption(""), has_spoiler_));
send_message(chat_id, td_api::make_object<td_api::inputMessageAnimation>(
as_input_file_id(file_id), nullptr, vector<int32>(), 0, 0, 0, as_caption(""),
show_caption_above_media_, has_spoiler_));
} else if (op == "sanurl") {
ChatId chat_id;
string url;
get_args(args, chat_id, url);
send_message(chat_id, td_api::make_object<td_api::inputMessageAnimation>(as_generated_file(url, "#url#"), nullptr,
vector<int32>(), 0, 0, 0, as_caption(""),
has_spoiler_));
send_message(chat_id, td_api::make_object<td_api::inputMessageAnimation>(
as_generated_file(url, "#url#"), nullptr, vector<int32>(), 0, 0, 0, as_caption(""),
show_caption_above_media_, has_spoiler_));
} else if (op == "sanurl2") {
ChatId chat_id;
string url;
get_args(args, chat_id, url);
send_message(chat_id, td_api::make_object<td_api::inputMessageAnimation>(
as_remote_file(url), nullptr, vector<int32>(), 0, 0, 0, as_caption(""), has_spoiler_));
as_remote_file(url), nullptr, vector<int32>(), 0, 0, 0, as_caption(""),
show_caption_above_media_, has_spoiler_));
} else if (op == "sau") {
ChatId chat_id;
string audio_path;
@ -5399,26 +5404,29 @@ class CliClient final : public Actor {
string caption;
string sticker_file_ids;
get_args(args, chat_id, photo, caption, sticker_file_ids);
send_message(chat_id, td_api::make_object<td_api::inputMessagePhoto>(
as_input_file(photo), nullptr, to_integers<int32>(sticker_file_ids), 0, 0,
as_caption(caption), get_message_self_destruct_type(), has_spoiler_));
send_message(chat_id,
td_api::make_object<td_api::inputMessagePhoto>(
as_input_file(photo), nullptr, to_integers<int32>(sticker_file_ids), 0, 0, as_caption(caption),
show_caption_above_media_, get_message_self_destruct_type(), has_spoiler_));
} else if (op == "spg") {
ChatId chat_id;
string photo_path;
string conversion;
int64 expected_size;
get_args(args, chat_id, photo_path, conversion, expected_size);
send_message(chat_id, td_api::make_object<td_api::inputMessagePhoto>(
as_generated_file(photo_path, conversion, expected_size), nullptr, vector<int32>(), 0,
0, as_caption(""), get_message_self_destruct_type(), has_spoiler_));
send_message(chat_id,
td_api::make_object<td_api::inputMessagePhoto>(
as_generated_file(photo_path, conversion, expected_size), nullptr, vector<int32>(), 0, 0,
as_caption(""), show_caption_above_media_, get_message_self_destruct_type(), has_spoiler_));
} else if (op == "spt") {
ChatId chat_id;
string photo_path;
string thumbnail_path;
get_args(args, chat_id, photo_path, thumbnail_path);
send_message(chat_id, td_api::make_object<td_api::inputMessagePhoto>(
as_input_file(photo_path), as_input_thumbnail(thumbnail_path, 90, 89), vector<int32>(),
0, 0, as_caption(""), get_message_self_destruct_type(), has_spoiler_));
send_message(chat_id,
td_api::make_object<td_api::inputMessagePhoto>(
as_input_file(photo_path), as_input_thumbnail(thumbnail_path, 90, 89), vector<int32>(), 0, 0,
as_caption(""), show_caption_above_media_, get_message_self_destruct_type(), has_spoiler_));
} else if (op == "sptg") {
ChatId chat_id;
string photo_path;
@ -5428,7 +5436,8 @@ class CliClient final : public Actor {
send_message(chat_id,
td_api::make_object<td_api::inputMessagePhoto>(
as_input_file(photo_path), as_input_thumbnail(thumbnail_path, thumbnail_conversion, 90, 89),
vector<int32>(), 0, 0, as_caption(""), get_message_self_destruct_type(), has_spoiler_));
vector<int32>(), 0, 0, as_caption(""), show_caption_above_media_,
get_message_self_destruct_type(), has_spoiler_));
} else if (op == "spgtg") {
ChatId chat_id;
string photo_path;
@ -5436,17 +5445,18 @@ class CliClient final : public Actor {
string thumbnail_path;
string thumbnail_conversion;
get_args(args, chat_id, photo_path, conversion, thumbnail_path, thumbnail_conversion);
send_message(chat_id, td_api::make_object<td_api::inputMessagePhoto>(
as_generated_file(photo_path, conversion),
as_input_thumbnail(thumbnail_path, thumbnail_conversion, 90, 89), vector<int32>(), 0, 0,
as_caption(""), get_message_self_destruct_type(), has_spoiler_));
send_message(chat_id,
td_api::make_object<td_api::inputMessagePhoto>(
as_generated_file(photo_path, conversion),
as_input_thumbnail(thumbnail_path, thumbnail_conversion, 90, 89), vector<int32>(), 0, 0,
as_caption(""), show_caption_above_media_, get_message_self_destruct_type(), has_spoiler_));
} else if (op == "spid") {
ChatId chat_id;
string file_id;
get_args(args, chat_id, file_id);
send_message(chat_id, td_api::make_object<td_api::inputMessagePhoto>(
as_input_file_id(file_id), nullptr, vector<int32>(), 0, 0, as_caption(""),
get_message_self_destruct_type(), has_spoiler_));
show_caption_above_media_, get_message_self_destruct_type(), has_spoiler_));
} else if (op == "ss") {
ChatId chat_id;
string sticker_path;
@ -5484,17 +5494,19 @@ class CliClient final : public Actor {
} else {
sticker_file_ids = to_integers<int32>(sticker_file_ids_str);
}
send_message(chat_id, td_api::make_object<td_api::inputMessageVideo>(
as_input_file(video_path), nullptr, std::move(sticker_file_ids), 1, 2, 3, true,
as_caption(""), get_message_self_destruct_type(), has_spoiler_));
send_message(chat_id,
td_api::make_object<td_api::inputMessageVideo>(
as_input_file(video_path), nullptr, std::move(sticker_file_ids), 1, 2, 3, true, as_caption(""),
show_caption_above_media_, get_message_self_destruct_type(), has_spoiler_));
} else if (op == "svt") {
ChatId chat_id;
string video;
string thumbnail;
get_args(args, chat_id, video, thumbnail);
send_message(chat_id, td_api::make_object<td_api::inputMessageVideo>(
as_input_file(video), as_input_thumbnail(thumbnail), vector<int32>(), 0, 0, 0, true,
as_caption(""), get_message_self_destruct_type(), has_spoiler_));
send_message(chat_id,
td_api::make_object<td_api::inputMessageVideo>(
as_input_file(video), as_input_thumbnail(thumbnail), vector<int32>(), 0, 0, 0, true,
as_caption(""), show_caption_above_media_, get_message_self_destruct_type(), has_spoiler_));
} else if (op == "svn") {
ChatId chat_id;
string video_path;
@ -7013,6 +7025,7 @@ class CliClient final : public Actor {
bool link_preview_force_small_media_ = false;
bool link_preview_force_large_media_ = false;
bool link_preview_show_above_text_ = false;
bool show_caption_above_media_ = false;
int64 saved_messages_topic_id_ = 0;
string quick_reply_shortcut_name_;