Add flag messageSendOptions.protect_content.

This commit is contained in:
levlam 2021-12-28 18:19:19 +03:00
parent 20a460aeb3
commit ed766a4d2f
4 changed files with 25 additions and 6 deletions

View File

@ -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

View File

@ -23799,6 +23799,7 @@ unique_ptr<MessagesManager::Message> 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::MessageSendOptions> 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::MessageSendOptions> 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<int64> random_ids =
transform(messages, [this, to_dialog_id](const Message *m) { return begin_send_message(to_dialog_id, m); });
@ -27399,7 +27411,7 @@ Result<vector<MessageId>> 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,

View File

@ -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) {
}
};

View File

@ -1618,14 +1618,15 @@ class CliClient final : public Actor {
auto chat = as_chat_id(chat_id);
auto id = send_request(td_api::make_object<td_api::sendMessage>(
chat, as_message_thread_id(message_thread_id_), reply_to_message_id,
td_api::make_object<td_api::messageSendOptions>(disable_notification, from_background,
td_api::make_object<td_api::messageSendOptions>(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<td_api::messageSendOptions> default_message_send_options() const {
return td_api::make_object<td_api::messageSendOptions>(false, false, as_message_scheduling_state(schedule_date_));
return td_api::make_object<td_api::messageSendOptions>(false, false, false,
as_message_scheduling_state(schedule_date_));
}
void send_get_background_url(td_api::object_ptr<td_api::BackgroundType> &&background_type) {