diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index d973c2be5..2b7fb44e2 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1951,8 +1951,9 @@ messageSchedulingStateSendWhenOnline = MessageSchedulingState; //@description Options to be used when a message is sent //@disable_notification Pass true to disable notification for the message //@from_background Pass true if the message is sent from the background +//@protect_content Pass true if the content of the message must be protected from forwarding and saving; for bots only //@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 scheduling_state:MessageSchedulingState = MessageSendOptions; +messageSendOptions disable_notification:Bool from_background:Bool protect_content:Bool scheduling_state:MessageSchedulingState = 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 1c406f18a..77c3389d9 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -23799,6 +23799,7 @@ unique_ptr MessagesManager::create_message_to_send( m->is_channel_post = is_channel_post; m->is_outgoing = is_scheduled || dialog_id != DialogId(my_id); m->from_background = options.from_background; + m->noforwards = options.protect_content; m->view_count = is_channel_post && !is_scheduled ? 1 : 0; m->forward_count = 0; if ([&] { @@ -24433,6 +24434,7 @@ Result MessagesManager::process_message_sen if (options != nullptr) { result.disable_notification = options->disable_notification_; result.from_background = options->from_background_; + result.protect_content = options->protect_content_; TRY_RESULT_ASSIGN(result.schedule_date, get_message_schedule_date(std::move(options->scheduling_state_))); } @@ -24454,6 +24456,10 @@ Result MessagesManager::process_message_sen } } + if (result.protect_content && !td_->auth_manager_->is_bot()) { + result.protect_content = false; + } + return result; } @@ -26581,6 +26587,9 @@ int32 MessagesManager::get_message_flags(const Message *m) { if (m->message_id.is_scheduled()) { flags |= SEND_MESSAGE_FLAG_HAS_SCHEDULE_DATE; } + if (m->noforwards) { + flags |= SEND_MESSAGE_FLAG_NOFORWARDS; + } return flags; } @@ -26890,6 +26899,9 @@ void MessagesManager::do_forward_messages(DialogId to_dialog_id, DialogId from_d if (messages[0]->has_explicit_sender) { flags |= SEND_MESSAGE_FLAG_HAS_SEND_AS; } + if (messages[0]->noforwards) { + flags |= SEND_MESSAGE_FLAG_NOFORWARDS; + } vector random_ids = transform(messages, [this, to_dialog_id](const Message *m) { return begin_send_message(to_dialog_id, m); }); @@ -27399,7 +27411,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, + MessageSendOptions options(message->disable_notification, message->from_background, message->noforwards, get_message_schedule_date(message.get())); Message *m = get_message_to_send( d, message->top_thread_message_id, diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 2058200e0..f1a1a4521 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -135,6 +135,7 @@ class MessagesManager final : public Actor { static constexpr int32 SEND_MESSAGE_FLAG_HAS_SCHEDULE_DATE = 1 << 10; static constexpr int32 SEND_MESSAGE_FLAG_HAS_MESSAGE = 1 << 11; static constexpr int32 SEND_MESSAGE_FLAG_HAS_SEND_AS = 1 << 13; + static constexpr int32 SEND_MESSAGE_FLAG_NOFORWARDS = 1 << 14; static constexpr int32 ONLINE_MEMBER_COUNT_CACHE_EXPIRE_TIME = 30 * 60; @@ -1651,11 +1652,15 @@ class MessagesManager final : public Actor { struct MessageSendOptions { bool disable_notification = false; bool from_background = false; + bool protect_content = false; int32 schedule_date = 0; MessageSendOptions() = default; - MessageSendOptions(bool disable_notification, bool from_background, int32 schedule_date) - : disable_notification(disable_notification), from_background(from_background), schedule_date(schedule_date) { + MessageSendOptions(bool disable_notification, bool from_background, bool protect_content, int32 schedule_date) + : disable_notification(disable_notification) + , from_background(from_background) + , protect_content(protect_content) + , schedule_date(schedule_date) { } }; diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 5809a5d12..ed0d2c37c 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1618,14 +1618,15 @@ class CliClient final : public Actor { auto chat = as_chat_id(chat_id); auto id = send_request(td_api::make_object( chat, as_message_thread_id(message_thread_id_), reply_to_message_id, - td_api::make_object(disable_notification, from_background, + td_api::make_object(disable_notification, from_background, true, as_message_scheduling_state(schedule_date_)), nullptr, std::move(input_message_content))); query_id_to_send_message_info_[id].start_time = Time::now(); } td_api::object_ptr default_message_send_options() const { - return td_api::make_object(false, false, as_message_scheduling_state(schedule_date_)); + return td_api::make_object(false, false, false, + as_message_scheduling_state(schedule_date_)); } void send_get_background_url(td_api::object_ptr &&background_type) {