From 4434bd327a2d1ab7d95d6a4252541d79afdd900f Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 16 May 2024 12:42:36 +0300 Subject: [PATCH] Allow to edit show_caption_above_media. --- td/generate/scheme/td_api.tl | 6 ++++-- td/telegram/MessagesManager.cpp | 22 +++++++++++++--------- td/telegram/MessagesManager.h | 6 ++++-- td/telegram/Td.cpp | 13 ++++++++----- td/telegram/cli.cpp | 3 ++- 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 8acc6d78b..a93a218dd 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -8190,7 +8190,8 @@ editMessageMedia chat_id:int53 message_id:int53 reply_markup:ReplyMarkup input_m //@message_id Identifier of the message //@reply_markup The new message reply markup; pass null if none; for bots only //@caption New message content caption; 0-getOption("message_caption_length_max") characters; pass null to remove caption -editMessageCaption chat_id:int53 message_id:int53 reply_markup:ReplyMarkup caption:formattedText = Message; +//@show_caption_above_media True, if caption must be shown above the media; otherwise caption must be shown below the media. Can be true only for animation, photo, and video messages +editMessageCaption chat_id:int53 message_id:int53 reply_markup:ReplyMarkup caption:formattedText show_caption_above_media:Bool = Message; //@description Edits the message reply markup; for bots only. Returns the edited message after the edit is completed on the server side //@chat_id The chat the message belongs to @@ -8224,7 +8225,8 @@ editInlineMessageMedia inline_message_id:string reply_markup:ReplyMarkup input_m //@inline_message_id Inline message identifier //@reply_markup The new message reply markup; pass null if none //@caption New message content caption; pass null to remove caption; 0-getOption("message_caption_length_max") characters -editInlineMessageCaption inline_message_id:string reply_markup:ReplyMarkup caption:formattedText = Ok; +//@show_caption_above_media True, if caption must be shown above the media; otherwise caption must be shown below the media. Can be true only for animation, photo, and video messages +editInlineMessageCaption inline_message_id:string reply_markup:ReplyMarkup caption:formattedText show_caption_above_media:Bool = Ok; //@description Edits the reply markup of an inline message sent via a bot; for bots only //@inline_message_id Inline message identifier diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index a49514a23..9bc7aba78 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -25096,7 +25096,7 @@ void MessagesManager::edit_message_live_location(MessageFullId message_full_id, flags, false /*ignored*/, location.get_input_geo_point(), heading, live_period, proximity_alert_radius); td_->create_handler(std::move(promise)) ->send(0, dialog_id, m->message_id, string(), vector>(), - std::move(input_media), false, std::move(input_reply_markup), get_message_schedule_date(m)); + std::move(input_media), false /*ignored*/, std::move(input_reply_markup), get_message_schedule_date(m)); } void MessagesManager::cancel_edit_message_media(DialogId dialog_id, Message *m, Slice error_message) { @@ -25282,7 +25282,7 @@ void MessagesManager::edit_message_media(MessageFullId message_full_id, void MessagesManager::edit_message_caption(MessageFullId message_full_id, tl_object_ptr &&reply_markup, - tl_object_ptr &&input_caption, + tl_object_ptr &&input_caption, bool invert_media, Promise &&promise) { auto dialog_id = message_full_id.get_dialog_id(); TRY_RESULT_PROMISE(promise, d, check_dialog_access(dialog_id, true, AccessRights::Edit, "edit_message_caption")); @@ -25298,6 +25298,9 @@ void MessagesManager::edit_message_caption(MessageFullId message_full_id, if (!can_have_message_content_caption(m->content->get_type())) { return promise.set_error(Status::Error(400, "There is no caption in the message to edit")); } + if (invert_media && !is_allowed_invert_caption_message_content(m->content->get_type())) { + invert_media = false; + } TRY_RESULT_PROMISE( promise, caption, @@ -25310,7 +25313,7 @@ void MessagesManager::edit_message_caption(MessageFullId message_full_id, td_->create_handler(std::move(promise)) ->send(1 << 11, dialog_id, m->message_id, caption.text, get_input_message_entities(td_->user_manager_.get(), caption.entities, "edit_message_caption"), nullptr, - m->invert_media, std::move(input_reply_markup), get_message_schedule_date(m)); + invert_media, std::move(input_reply_markup), get_message_schedule_date(m)); } void MessagesManager::edit_message_reply_markup(MessageFullId message_full_id, @@ -25335,7 +25338,7 @@ void MessagesManager::edit_message_reply_markup(MessageFullId message_full_id, auto input_reply_markup = get_input_reply_markup(td_->user_manager_.get(), new_reply_markup); td_->create_handler(std::move(promise)) ->send(0, dialog_id, m->message_id, string(), vector>(), nullptr, - m->invert_media, std::move(input_reply_markup), get_message_schedule_date(m)); + m->invert_media /*ignored*/, std::move(input_reply_markup), get_message_schedule_date(m)); } void MessagesManager::edit_inline_message_text(const string &inline_message_id, @@ -25410,7 +25413,8 @@ void MessagesManager::edit_inline_message_live_location(const string &inline_mes flags, false /*ignored*/, location.get_input_geo_point(), heading, live_period, proximity_alert_radius); td_->create_handler(std::move(promise)) ->send(0, std::move(input_bot_inline_message_id), "", vector>(), - std::move(input_media), false, get_input_reply_markup(td_->user_manager_.get(), new_reply_markup)); + std::move(input_media), false /*ignored*/, + get_input_reply_markup(td_->user_manager_.get(), new_reply_markup)); } void MessagesManager::edit_inline_message_media(const string &inline_message_id, @@ -25460,7 +25464,7 @@ void MessagesManager::edit_inline_message_media(const string &inline_message_id, void MessagesManager::edit_inline_message_caption(const string &inline_message_id, tl_object_ptr &&reply_markup, tl_object_ptr &&input_caption, - Promise &&promise) { + bool invert_media, Promise &&promise) { CHECK(td_->auth_manager_->is_bot()); TRY_RESULT_PROMISE(promise, caption, @@ -25477,7 +25481,7 @@ void MessagesManager::edit_inline_message_caption(const string &inline_message_i td_->create_handler(std::move(promise)) ->send(1 << 11, std::move(input_bot_inline_message_id), caption.text, get_input_message_entities(td_->user_manager_.get(), caption.entities, "edit_inline_message_caption"), - nullptr, false, get_input_reply_markup(td_->user_manager_.get(), new_reply_markup)); + nullptr, invert_media, get_input_reply_markup(td_->user_manager_.get(), new_reply_markup)); } void MessagesManager::edit_inline_message_reply_markup(const string &inline_message_id, @@ -25495,7 +25499,7 @@ void MessagesManager::edit_inline_message_reply_markup(const string &inline_mess td_->create_handler(std::move(promise)) ->send(0, std::move(input_bot_inline_message_id), string(), vector>(), - nullptr, false, get_input_reply_markup(td_->user_manager_.get(), new_reply_markup)); + nullptr, false /*ignored*/, get_input_reply_markup(td_->user_manager_.get(), new_reply_markup)); } void MessagesManager::edit_message_scheduling_state( @@ -25527,7 +25531,7 @@ void MessagesManager::edit_message_scheduling_state( if (schedule_date > 0) { td_->create_handler(std::move(promise)) ->send(0, dialog_id, m->message_id, string(), vector>(), nullptr, - m->invert_media, nullptr, schedule_date); + m->invert_media /*ignored*/, nullptr, schedule_date); } else { td_->create_handler(std::move(promise))->send(dialog_id, m->message_id); } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index bdeb99de4..93547dc76 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -476,7 +476,8 @@ class MessagesManager final : public Actor { tl_object_ptr &&input_message_content, Promise &&promise); void edit_message_caption(MessageFullId message_full_id, tl_object_ptr &&reply_markup, - tl_object_ptr &&input_caption, Promise &&promise); + tl_object_ptr &&input_caption, bool invert_media, + Promise &&promise); void edit_message_reply_markup(MessageFullId message_full_id, tl_object_ptr &&reply_markup, Promise &&promise); @@ -495,7 +496,8 @@ class MessagesManager final : public Actor { Promise &&promise); void edit_inline_message_caption(const string &inline_message_id, tl_object_ptr &&reply_markup, - tl_object_ptr &&input_caption, Promise &&promise); + tl_object_ptr &&input_caption, bool invert_media, + Promise &&promise); void edit_inline_message_reply_markup(const string &inline_message_id, tl_object_ptr &&reply_markup, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 5aafdc581..944ee8b88 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -1271,10 +1271,11 @@ class EditMessageCaptionRequest final : public RequestOnceActor { MessageFullId message_full_id_; tl_object_ptr reply_markup_; tl_object_ptr caption_; + bool invert_media_; void do_run(Promise &&promise) final { td_->messages_manager_->edit_message_caption(message_full_id_, std::move(reply_markup_), std::move(caption_), - std::move(promise)); + invert_media_, std::move(promise)); } void do_send_result() final { @@ -1284,11 +1285,12 @@ class EditMessageCaptionRequest final : public RequestOnceActor { public: EditMessageCaptionRequest(ActorShared td, uint64 request_id, int64 dialog_id, int64 message_id, tl_object_ptr reply_markup, - tl_object_ptr caption) + tl_object_ptr caption, bool invert_media) : RequestOnceActor(std::move(td), request_id) , message_full_id_(DialogId(dialog_id), MessageId(message_id)) , reply_markup_(std::move(reply_markup)) - , caption_(std::move(caption)) { + , caption_(std::move(caption)) + , invert_media_(invert_media) { } }; @@ -5704,7 +5706,7 @@ void Td::on_request(uint64 id, td_api::editMessageMedia &request) { void Td::on_request(uint64 id, td_api::editMessageCaption &request) { CREATE_REQUEST(EditMessageCaptionRequest, request.chat_id_, request.message_id_, std::move(request.reply_markup_), - std::move(request.caption_)); + std::move(request.caption_), request.show_caption_above_media_); } void Td::on_request(uint64 id, td_api::editMessageReplyMarkup &request) { @@ -5743,7 +5745,8 @@ void Td::on_request(uint64 id, td_api::editInlineMessageCaption &request) { CLEAN_INPUT_STRING(request.inline_message_id_); CREATE_OK_REQUEST_PROMISE(); messages_manager_->edit_inline_message_caption(request.inline_message_id_, std::move(request.reply_markup_), - std::move(request.caption_), std::move(promise)); + std::move(request.caption_), request.show_caption_above_media_, + std::move(promise)); } void Td::on_request(uint64 id, td_api::editInlineMessageReplyMarkup &request) { diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 13c76caa2..0ce4f0cbd 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4990,7 +4990,8 @@ class CliClient final : public Actor { MessageId message_id; string caption; get_args(args, chat_id, message_id, caption); - send_request(td_api::make_object(chat_id, message_id, nullptr, as_caption(caption))); + send_request(td_api::make_object(chat_id, message_id, nullptr, as_caption(caption), + show_caption_above_media_)); } else if (op == "emd") { ChatId chat_id; MessageId message_id;