From faf964a10d7c4833b8f392f8e3ed5078fc3d2382 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 23 Oct 2023 18:40:55 +0300 Subject: [PATCH] Move only_preview to messageSendOptions. --- td/generate/scheme/td_api.tl | 9 ++++----- td/telegram/MessagesManager.cpp | 31 ++++++++++++++++--------------- td/telegram/MessagesManager.h | 17 ++++++++--------- td/telegram/Td.cpp | 5 ++--- td/telegram/cli.cpp | 23 ++++++++++++----------- 5 files changed, 42 insertions(+), 43 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 9b8b5abda..0b2ff2913 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2968,7 +2968,8 @@ messageSelfDestructTypeImmediately = MessageSelfDestructType; //@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 //@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; +//@only_preview Pass true to get a fake message instead of actually sending them +messageSendOptions disable_notification:Bool from_background:Bool protect_content:Bool update_order_of_installed_sticker_sets:Bool scheduling_state:MessageSchedulingState sending_id:int32 only_preview:Bool = 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 @@ -6996,8 +6997,7 @@ sendMessage chat_id:int53 message_thread_id:int53 reply_to:InputMessageReplyTo o //@reply_to Identifier of the replied message or story; pass null if none //@options Options to be used to send the messages; pass null to use default options //@input_message_contents Contents of messages to be sent. At most 10 messages can be added to an album -//@only_preview Pass true to get fake messages instead of actually sending them -sendMessageAlbum chat_id:int53 message_thread_id:int53 reply_to:InputMessageReplyTo options:messageSendOptions input_message_contents:vector only_preview:Bool = Messages; +sendMessageAlbum chat_id:int53 message_thread_id:int53 reply_to:InputMessageReplyTo options:messageSendOptions input_message_contents:vector = Messages; //@description Invites a bot to a chat (if it is not yet a member) and sends it the /start command. Bots can't be invited to a private chat other than the chat with the bot. Bots can't be invited to channels (although they can be added as admins) and secret chats. Returns the sent message //@bot_user_id Identifier of the bot @@ -7023,8 +7023,7 @@ sendInlineQueryResultMessage chat_id:int53 message_thread_id:int53 reply_to:Inpu //@options Options to be used to send the messages; pass null to use default options //@send_copy Pass true to copy content of the messages without reference to the original sender. Always true if the messages are forwarded to a secret chat or are local //@remove_caption Pass true to remove media captions of message copies. Ignored if send_copy is false -//@only_preview Pass true to get fake messages instead of actually forwarding them -forwardMessages chat_id:int53 message_thread_id:int53 from_chat_id:int53 message_ids:vector options:messageSendOptions send_copy:Bool remove_caption:Bool only_preview:Bool = Messages; +forwardMessages chat_id:int53 message_thread_id:int53 from_chat_id:int53 message_ids:vector options:messageSendOptions send_copy:Bool remove_caption:Bool = Messages; //@description Resends messages which failed to send. Can be called only for messages for which messageSendingStateFailed.can_retry is true and after specified in messageSendingStateFailed.retry_after time passed. //-If a message is re-sent, the corresponding failed to send message is deleted. Returns the sent messages in the same order as the message identifiers passed in message_ids. If a message can't be re-sent, null will be returned instead of the message diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index f70416980..fee003596 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -25030,6 +25030,7 @@ Result MessagesManager::process_message_sen result.update_stickersets_order = options->update_order_of_installed_sticker_sets_; } result.protect_content = options->protect_content_; + result.only_preview = options->only_preview_; TRY_RESULT_ASSIGN(result.schedule_date, get_message_schedule_date(std::move(options->scheduling_state_))); result.sending_id = options->sending_id_; } @@ -25123,7 +25124,7 @@ int64 MessagesManager::generate_new_media_album_id() { Result> MessagesManager::send_message_group( DialogId dialog_id, MessageId top_thread_message_id, td_api::object_ptr &&reply_to, tl_object_ptr &&options, - vector> &&input_message_contents, bool only_preview) { + vector> &&input_message_contents) { if (input_message_contents.size() > MAX_GROUPED_MESSAGES) { return Status::Error(400, "Too many messages to send as an album"); } @@ -25176,7 +25177,7 @@ Result> MessagesManager::send_message_group auto &message_content = message_contents[i]; unique_ptr message; Message *m; - if (only_preview) { + if (message_send_options.only_preview) { message = create_message_to_send(d, top_thread_message_id, input_reply_to, message_send_options, std::move(message_content.content), message_content.invert_media, i != 0, nullptr, false, DialogId()); @@ -25201,7 +25202,7 @@ Result> MessagesManager::send_message_group result.push_back(get_message_object(dialog_id, m, "send_message_group")); - if (!only_preview) { + if (!message_send_options.only_preview) { save_send_message_log_event(dialog_id, m); do_send_message(dialog_id, m); @@ -25212,7 +25213,7 @@ Result> MessagesManager::send_message_group } if (need_update_dialog_pos) { - CHECK(!only_preview); + CHECK(!message_send_options.only_preview); send_update_chat_last_message(d, "send_message_group"); } @@ -27688,7 +27689,7 @@ Result> MessagesManager::forward_message( vector all_copy_options; all_copy_options.push_back(std::move(copy_options)); TRY_RESULT(result, forward_messages(to_dialog_id, top_thread_message_id, from_dialog_id, {message_id}, - std::move(options), in_game_share, std::move(all_copy_options), false)); + std::move(options), in_game_share, std::move(all_copy_options))); CHECK(result->messages_.size() == 1); if (result->messages_[0] == nullptr) { return Status::Error(400, @@ -28023,14 +28024,14 @@ Result MessagesManager::get_forwarded_messag Result> MessagesManager::forward_messages( DialogId to_dialog_id, MessageId top_thread_message_id, DialogId from_dialog_id, vector message_ids, - tl_object_ptr &&options, bool in_game_share, vector &©_options, - bool only_preview) { + tl_object_ptr &&options, bool in_game_share, + vector &©_options) { TRY_RESULT(forwarded_messages_info, get_forwarded_messages(to_dialog_id, top_thread_message_id, from_dialog_id, message_ids, std::move(options), in_game_share, std::move(copy_options))); auto from_dialog = forwarded_messages_info.from_dialog; auto to_dialog = forwarded_messages_info.to_dialog; - auto message_send_options = forwarded_messages_info.message_send_options; + const auto message_send_options = forwarded_messages_info.message_send_options; auto &copied_messages = forwarded_messages_info.copied_messages; auto &forwarded_message_contents = forwarded_messages_info.forwarded_message_contents; auto drop_author = forwarded_messages_info.drop_author; @@ -28063,7 +28064,7 @@ Result> MessagesManager::forward_messages( unique_ptr message; Message *m; - if (only_preview) { + if (message_send_options.only_preview) { message = create_message_to_send( to_dialog, top_thread_message_id, MessageInputReplyTo{reply_to_message_id}, message_send_options, std::move(content), forwarded_message_contents[j].invert_media, j + 1 != forwarded_message_contents.size(), @@ -28087,7 +28088,7 @@ Result> MessagesManager::forward_messages( m->real_forward_from_message_id = message_id; forwarded_message_id_to_new_message_id.emplace(message_id, m->message_id); - if (!only_preview) { + if (!message_send_options.only_preview) { if (!td_->auth_manager_->is_bot()) { send_update_new_message(to_dialog, m); } @@ -28099,7 +28100,7 @@ Result> MessagesManager::forward_messages( } if (!forwarded_messages.empty()) { - CHECK(!only_preview); + CHECK(!message_send_options.only_preview); do_forward_messages(to_dialog_id, from_dialog_id, forwarded_messages, forwarded_message_ids, drop_author, drop_media_captions, 0); } @@ -28127,7 +28128,7 @@ Result> MessagesManager::forward_messages( unique_ptr message; Message *m; - if (only_preview) { + if (message_send_options.only_preview) { message = create_message_to_send(to_dialog, top_thread_message_id, input_reply_to, message_send_options, std::move(copied_message.content), copied_message.invert_media, false, nullptr, is_copy, DialogId()); @@ -28153,7 +28154,7 @@ Result> MessagesManager::forward_messages( m->reply_markup = std::move(copied_message.reply_markup); forwarded_message_id_to_new_message_id[copied_message.original_message_id] = m->message_id; - if (!only_preview) { + if (!message_send_options.only_preview) { save_send_message_log_event(to_dialog_id, m); do_send_message(to_dialog_id, m); if (!td_->auth_manager_->is_bot()) { @@ -28165,7 +28166,7 @@ Result> MessagesManager::forward_messages( } if (need_update_dialog_pos) { - CHECK(!only_preview); + CHECK(!message_send_options.only_preview); send_update_chat_last_message(to_dialog, "forward_messages"); } @@ -28266,7 +28267,7 @@ Result> MessagesManager::resend_messages(DialogId dialog_id, v auto need_another_sender = 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, + message->update_stickersets_order, message->noforwards, false, get_message_schedule_date(message.get()), message->sending_id); Message *m = get_message_to_send(d, message->top_thread_message_id, get_message_input_reply_to(message.get()), options, diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index bd4845b54..20c236741 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -442,8 +442,7 @@ class MessagesManager final : public Actor { Result> send_message_group( DialogId dialog_id, MessageId top_thread_message_id, td_api::object_ptr &&reply_to, tl_object_ptr &&options, - vector> &&input_message_contents, - bool only_preview) TD_WARN_UNUSED_RESULT; + vector> &&input_message_contents) TD_WARN_UNUSED_RESULT; Result send_bot_start_message(UserId bot_user_id, DialogId dialog_id, const string ¶meter) TD_WARN_UNUSED_RESULT; @@ -454,12 +453,10 @@ class MessagesManager final : public Actor { int64 query_id, const string &result_id, bool hide_via_bot) TD_WARN_UNUSED_RESULT; - Result> forward_messages(DialogId to_dialog_id, MessageId top_thread_message_id, - DialogId from_dialog_id, vector message_ids, - tl_object_ptr &&options, - bool in_game_share, - vector &©_options, - bool only_preview) TD_WARN_UNUSED_RESULT; + Result> forward_messages( + DialogId to_dialog_id, MessageId top_thread_message_id, DialogId from_dialog_id, vector message_ids, + tl_object_ptr &&options, bool in_game_share, + vector &©_options) TD_WARN_UNUSED_RESULT; Result> resend_messages(DialogId dialog_id, vector message_ids) TD_WARN_UNUSED_RESULT; @@ -1581,16 +1578,18 @@ class MessagesManager final : public Actor { bool from_background = false; bool update_stickersets_order = false; bool protect_content = false; + bool only_preview = 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, int32 sending_id) + bool protect_content, bool only_preview, int32 schedule_date, int32 sending_id) : disable_notification(disable_notification) , from_background(from_background) , update_stickersets_order(update_stickersets_order) , protect_content(protect_content) + , only_preview(only_preview) , schedule_date(schedule_date) , sending_id(sending_id) { } diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 9bcab83db..e2024d215 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5582,7 +5582,7 @@ void Td::on_request(uint64 id, td_api::sendMessage &request) { void Td::on_request(uint64 id, td_api::sendMessageAlbum &request) { auto r_messages = messages_manager_->send_message_group( DialogId(request.chat_id_), MessageId(request.message_thread_id_), std::move(request.reply_to_), - std::move(request.options_), std::move(request.input_message_contents_), request.only_preview_); + std::move(request.options_), std::move(request.input_message_contents_)); if (r_messages.is_error()) { send_closure(actor_id(this), &Td::send_error, id, r_messages.move_as_error()); } else { @@ -5905,8 +5905,7 @@ void Td::on_request(uint64 id, td_api::forwardMessages &request) { MessageId) { return MessageCopyOptions(send_copy, remove_caption); }); auto r_messages = messages_manager_->forward_messages( DialogId(request.chat_id_), MessageId(request.message_thread_id_), DialogId(request.from_chat_id_), - std::move(input_message_ids), std::move(request.options_), false, std::move(message_copy_options), - request.only_preview_); + std::move(input_message_ids), std::move(request.options_), false, std::move(message_copy_options)); if (r_messages.is_error()) { send_closure(actor_id(this), &Td::send_error, id, r_messages.move_as_error()); } else { diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 90b9fa056..aac27eeee 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2284,7 +2284,7 @@ class CliClient final : public Actor { chat_id, message_thread_id_, reply_to, td_api::make_object(disable_notification, from_background, true, true, as_message_scheduling_state(schedule_date_), - Random::fast(1, 1000)), + Random::fast(1, 1000), only_preview_), nullptr, std::move(input_message_content))); if (id != 0) { query_id_to_send_message_info_[id].start_time = Time::now(); @@ -2293,7 +2293,7 @@ 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_), Random::fast(1, 1000)); + false, false, false, true, as_message_scheduling_state(schedule_date_), Random::fast(1, 1000), only_preview_); } void send_get_background_url(td_api::object_ptr &&background_type) { @@ -3711,7 +3711,7 @@ class CliClient final : public Actor { string message_ids; get_args(args, chat_id, message_ids); send_request(td_api::make_object(chat_id, as_message_ids(message_ids), op == "dmr")); - } else if (op == "fm" || op == "cm" || op == "fmp" || op == "cmp") { + } else if (op == "fm" || op == "cm") { ChatId chat_id; ChatId from_chat_id; string message_ids; @@ -3719,7 +3719,7 @@ class CliClient final : public Actor { get_args(args, chat_id, from_chat_id, message_ids, message_thread_id); send_request(td_api::make_object( chat_id, message_thread_id, from_chat_id, as_message_ids(message_ids), default_message_send_options(), - op[0] == 'c', rand_bool(), op.back() == 'p')); + op[0] == 'c', rand_bool())); } else if (op == "resend") { ChatId chat_id; string message_ids; @@ -4472,6 +4472,8 @@ class CliClient final : public Actor { as_search_messages_filter(filter))); } else if (op == "ssd") { schedule_date_ = std::move(args); + } else if (op == "sop") { + only_preview_ = as_bool(args); } else if (op == "smti") { get_args(args, message_thread_id_); } else if (op == "shs") { @@ -4524,7 +4526,7 @@ class CliClient final : public Actor { send_request(td_api::make_object( chat_id, as_message_sender(sender_id), reply_to, false, td_api::make_object(as_formatted_text(message), nullptr, true))); - } else if (op == "smap" || op == "smapr" || op == "smapp" || op == "smaprp") { + } else if (op == "smap" || op == "smapr") { ChatId chat_id; InputMessageReplyTo reply_to; get_args(args, chat_id, args); @@ -4538,9 +4540,8 @@ class CliClient final : public Actor { return content; }); send_request(td_api::make_object( - chat_id, message_thread_id_, reply_to, default_message_send_options(), std::move(input_message_contents), - op == "smapp" || op == "smaprp")); - } else if (op == "smad" || op == "smadp") { + chat_id, message_thread_id_, reply_to, default_message_send_options(), std::move(input_message_contents))); + } else if (op == "smad") { ChatId chat_id; get_args(args, chat_id, args); auto input_message_contents = transform(full_split(args), [](const string &document) { @@ -4548,9 +4549,8 @@ class CliClient final : public Actor { td_api::make_object(as_input_file(document), nullptr, true, as_caption("")); return content; }); - send_request(td_api::make_object(chat_id, message_thread_id_, nullptr, - default_message_send_options(), - std::move(input_message_contents), op.back() == 'p')); + send_request(td_api::make_object( + chat_id, message_thread_id_, nullptr, default_message_send_options(), std::move(input_message_contents))); } else if (op == "gmft") { auto r_message_file_head = read_file_str(args, 2 << 10); if (r_message_file_head.is_error()) { @@ -6274,6 +6274,7 @@ class CliClient final : public Actor { int64 my_id_ = 0; td_api::object_ptr authorization_state_; string schedule_date_; + bool only_preview_ = false; MessageThreadId message_thread_id_; bool has_spoiler_ = false; int32 message_self_destruct_time_ = 0;