From 1f32ae3dfd3b0de16a66ae8455f654f5105c755d Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 23 Feb 2023 17:05:43 +0300 Subject: [PATCH] Add sending_id to messageSendOptions. --- td/generate/scheme/td_api.tl | 7 ++++--- td/telegram/MessagesManager.cpp | 7 +++++-- td/telegram/MessagesManager.h | 12 ++++++++---- td/telegram/cli.cpp | 7 ++++--- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index c01541578..17da7f5d3 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1079,8 +1079,8 @@ unreadReaction type:ReactionType sender_id:MessageSender is_big:Bool = UnreadRea //@class MessageSendingState @description Contains information about the sending state of the message -//@description The message is being sent now, but has not yet been delivered to the server -messageSendingStatePending = MessageSendingState; +//@description The message is being sent now, but has not yet been delivered to the server @sending_id Non-persistent message sending identifier, specified by the application +messageSendingStatePending sending_id:int32 = MessageSendingState; //@description The message failed to be sent //@error_code An error code; 0 if unknown @@ -2679,7 +2679,8 @@ messageSchedulingStateSendWhenOnline = MessageSchedulingState; //@protect_content Pass true if the content of the message must be protected from forwarding and saving; for bots only //@update_order_of_installed_sticker_sets Pass true if the user explicitly chosen a sticker or a custom emoji from an installed sticker set; applicable only to sendMessage and sendMessageAlbum //@scheduling_state Message scheduling state; pass null to send message immediately. Messages sent to a secret chat, live location messages and self-destructing messages can't be scheduled -messageSendOptions disable_notification:Bool from_background:Bool protect_content:Bool update_order_of_installed_sticker_sets:Bool scheduling_state:MessageSchedulingState = MessageSendOptions; +//@sending_id Non-persistent identifier, which will be returned back in messageSendingStatePending object and can be used to match sent messages and corresponding updateNewMessage updates +messageSendOptions disable_notification:Bool from_background:Bool protect_content:Bool update_order_of_installed_sticker_sets:Bool scheduling_state:MessageSchedulingState sending_id:int32 = MessageSendOptions; //@description Options to be used when a message content is copied without reference to the original sender. Service messages and messageInvoice can't be copied //@send_copy True, if content of the message needs to be copied without reference to the original sender. Always true if the message is forwarded to a secret chat or is local diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 29df19ce8..81302797a 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -25701,7 +25701,7 @@ Result MessagesManager::get_message_schedule_date( tl_object_ptr MessagesManager::get_message_sending_state_object(const Message *m) const { CHECK(m != nullptr); if (m->message_id.is_yet_unsent()) { - return td_api::make_object(); + return td_api::make_object(m->sending_id); } if (m->is_failed_to_send) { auto can_retry = can_resend_message(m); @@ -26032,6 +26032,7 @@ unique_ptr MessagesManager::create_message_to_send( m->content = std::move(content); m->forward_info = std::move(forward_info); m->is_copy = is_copy || m->forward_info != nullptr; + m->sending_id = options.sending_id; if (td_->auth_manager_->is_bot() || options.disable_notification || td_->option_manager_->get_option_boolean("ignore_default_disable_notification")) { @@ -26720,6 +26721,8 @@ Result MessagesManager::process_message_sen result.protect_content = false; } + result.sending_id = options->sending_id_; + return result; } @@ -29895,7 +29898,7 @@ Result> MessagesManager::resend_messages(DialogId dialog_id, v message->send_error_code == 400 && message->send_error_message == CSlice("SEND_AS_PEER_INVALID"); MessageSendOptions options(message->disable_notification, message->from_background, message->update_stickersets_order, message->noforwards, - get_message_schedule_date(message.get())); + get_message_schedule_date(message.get()), message->sending_id); Message *m = get_message_to_send( d, message->top_thread_message_id, get_reply_to_message_id(d, message->top_thread_message_id, message->reply_to_message_id, false), options, diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index cbd23ae16..91f73ffd9 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1138,6 +1138,7 @@ class MessagesManager final : public Actor { int32 date = 0; int32 edit_date = 0; int32 send_date = 0; + int32 sending_id = 0; int64 random_id = 0; @@ -1759,15 +1760,17 @@ class MessagesManager final : public Actor { bool update_stickersets_order = false; bool protect_content = false; int32 schedule_date = 0; + int32 sending_id = 0; MessageSendOptions() = default; MessageSendOptions(bool disable_notification, bool from_background, bool update_stickersets_order, - bool protect_content, int32 schedule_date) + bool protect_content, int32 schedule_date, int32 sending_id) : disable_notification(disable_notification) , from_background(from_background) , update_stickersets_order(update_stickersets_order) , protect_content(protect_content) - , schedule_date(schedule_date) { + , schedule_date(schedule_date) + , sending_id(sending_id) { } }; @@ -1925,6 +1928,7 @@ class MessagesManager final : public Actor { static Status can_use_message_send_options(const MessageSendOptions &options, const unique_ptr &content, int32 ttl); + static Status can_use_message_send_options(const MessageSendOptions &options, const InputMessageContent &content); Status can_use_top_thread_message_id(Dialog *d, MessageId top_thread_message_id, MessageId reply_to_message_id); @@ -2014,7 +2018,7 @@ class MessagesManager final : public Actor { Result> forward_message(DialogId to_dialog_id, MessageId top_thread_message_id, DialogId from_dialog_id, MessageId message_id, - tl_object_ptr &&options, + td_api::object_ptr &&options, bool in_game_share, MessageCopyOptions &©_options) TD_WARN_UNUSED_RESULT; @@ -2054,7 +2058,7 @@ class MessagesManager final : public Actor { Result get_forwarded_messages(DialogId to_dialog_id, MessageId top_thread_message_id, DialogId from_dialog_id, const vector &message_ids, - tl_object_ptr &&options, + td_api::object_ptr &&options, bool in_game_share, vector &©_options); void do_send_media(DialogId dialog_id, Message *m, FileId file_id, FileId thumbnail_file_id, diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 3b9fc3761..4d0b24f48 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1862,7 +1862,8 @@ class CliClient final : public Actor { auto id = send_request(td_api::make_object( chat_id, message_thread_id_, reply_to_message_id, td_api::make_object(disable_notification, from_background, true, true, - as_message_scheduling_state(schedule_date_)), + as_message_scheduling_state(schedule_date_), + Random::fast(1, 1000)), nullptr, std::move(input_message_content))); if (id != 0) { query_id_to_send_message_info_[id].start_time = Time::now(); @@ -1870,8 +1871,8 @@ class CliClient final : public Actor { } td_api::object_ptr default_message_send_options() const { - return td_api::make_object(false, false, false, true, - as_message_scheduling_state(schedule_date_)); + return td_api::make_object( + false, false, false, true, as_message_scheduling_state(schedule_date_), Random::fast(1, 1000)); } void send_get_background_url(td_api::object_ptr &&background_type) {