Support sending silent messages in secret chats.
GitOrigin-RevId: fe15f9526bd5066b596e7e31d28bd9bab20cf719
This commit is contained in:
parent
ca3d263c25
commit
e848087e24
@ -1693,7 +1693,7 @@ messageSchedulingStateSendWhenOnline = MessageSchedulingState;
|
||||
|
||||
|
||||
//@description Options to be used when a message is sent
|
||||
//@disable_notification Pass true to disable notification for the message. Must be false if the message is sent to a secret chat
|
||||
//@disable_notification Pass true to disable notification for the message
|
||||
//@from_background Pass true if the message is sent from the background
|
||||
//@scheduling_state Message scheduling state. 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;
|
||||
|
@ -20953,12 +20953,8 @@ Result<MessagesManager::MessageSendOptions> MessagesManager::process_message_sen
|
||||
}
|
||||
|
||||
auto dialog_type = dialog_id.get_type();
|
||||
bool is_secret = dialog_type == DialogType::SecretChat;
|
||||
if (result.disable_notification && is_secret) {
|
||||
return Status::Error(400, "Can't send messages with silent notifications to secret chats");
|
||||
}
|
||||
if (result.schedule_date != 0) {
|
||||
if (is_secret) {
|
||||
if (dialog_type == DialogType::SecretChat) {
|
||||
return Status::Error(400, "Can't schedule messages in secret chats");
|
||||
}
|
||||
if (td_->auth_manager_->is_bot()) {
|
||||
|
@ -324,7 +324,7 @@ void SecretChatActor::send_message_impl(tl_object_ptr<secret_api::DecryptedMessa
|
||||
int64 random_id = 0;
|
||||
downcast_call(*message, [&](auto &x) { random_id = x.random_id_; });
|
||||
|
||||
LOG(INFO) << "Send message: " << to_string(*message) << to_string(file);
|
||||
LOG(INFO) << "Send message: " << to_string(message) << to_string(file);
|
||||
|
||||
auto it = random_id_to_outbound_message_state_token_.find(random_id);
|
||||
if (it != random_id_to_outbound_message_state_token_.end()) {
|
||||
@ -344,6 +344,9 @@ void SecretChatActor::send_message_impl(tl_object_ptr<secret_api::DecryptedMessa
|
||||
.move_as_ok();
|
||||
binlog_event->need_notify_user = (flags & SendFlag::Push) == 0;
|
||||
binlog_event->is_external = (flags & SendFlag::External) != 0;
|
||||
binlog_event->is_silent = (message->get_id() == secret_api::decryptedMessage::ID &&
|
||||
(static_cast<const secret_api::decryptedMessage *>(message.get())->flags_ &
|
||||
secret_api::decryptedMessage::SILENT_MASK) != 0);
|
||||
if (message->get_id() == secret_api::decryptedMessageService::ID) {
|
||||
binlog_event->is_rewritable = false;
|
||||
auto service_message = move_tl_object_as<secret_api::decryptedMessageService>(message);
|
||||
@ -1467,13 +1470,21 @@ NetQueryPtr SecretChatActor::create_net_query(const logevent::OutboundSecretMess
|
||||
telegram_api::messages_sendEncryptedService(get_input_chat(), message.random_id,
|
||||
message.encrypted_message.clone()));
|
||||
} else if (message.file.empty()) {
|
||||
int32 flags = 0;
|
||||
if (message.is_silent) {
|
||||
flags |= telegram_api::messages_sendEncrypted::SILENT_MASK;
|
||||
}
|
||||
query = create_net_query(
|
||||
QueryType::Message, telegram_api::messages_sendEncrypted(0, false /*ignored*/, get_input_chat(),
|
||||
QueryType::Message, telegram_api::messages_sendEncrypted(flags, false /*ignored*/, get_input_chat(),
|
||||
message.random_id, message.encrypted_message.clone()));
|
||||
} else {
|
||||
int32 flags = 0;
|
||||
if (message.is_silent) {
|
||||
flags |= telegram_api::messages_sendEncryptedFile::SILENT_MASK;
|
||||
}
|
||||
query = create_net_query(QueryType::Message,
|
||||
telegram_api::messages_sendEncryptedFile(
|
||||
0, false /*ignored*/, get_input_chat(), message.random_id,
|
||||
flags, false /*ignored*/, get_input_chat(), message.random_id,
|
||||
message.encrypted_message.clone(), message.file.as_input_encrypted_file()));
|
||||
}
|
||||
if (!message.is_rewritable) {
|
||||
@ -1562,6 +1573,7 @@ Status SecretChatActor::outbound_rewrite_with_empty(uint64 state_id) {
|
||||
state->message->is_rewritable = false;
|
||||
state->message->is_external = false;
|
||||
state->message->need_notify_user = false;
|
||||
state->message->is_silent = true;
|
||||
state->message->file = logevent::EncryptedInputFile::from_input_encrypted_file(nullptr);
|
||||
binlog_rewrite(context_->binlog(), state->message->logevent_id(), LogEvent::HandlerType::SecretChats,
|
||||
create_storer(*state->message));
|
||||
|
@ -330,6 +330,7 @@ class OutboundSecretMessage : public SecretChatLogEventBase<OutboundSecretMessag
|
||||
bool is_rewritable = false;
|
||||
// should notify our parent about state of this message (using context and random_id)
|
||||
bool is_external = false;
|
||||
bool is_silent = false;
|
||||
|
||||
tl_object_ptr<secret_api::DecryptedMessageAction> action;
|
||||
uint64 crc = 0; // DEBUG;
|
||||
@ -360,6 +361,7 @@ class OutboundSecretMessage : public SecretChatLogEventBase<OutboundSecretMessag
|
||||
STORE_FLAG(has_action);
|
||||
STORE_FLAG(is_rewritable);
|
||||
STORE_FLAG(is_external);
|
||||
STORE_FLAG(is_silent);
|
||||
END_STORE_FLAGS();
|
||||
|
||||
if (has_action) {
|
||||
@ -390,6 +392,7 @@ class OutboundSecretMessage : public SecretChatLogEventBase<OutboundSecretMessag
|
||||
PARSE_FLAG(has_action);
|
||||
PARSE_FLAG(is_rewritable);
|
||||
PARSE_FLAG(is_external);
|
||||
PARSE_FLAG(is_silent);
|
||||
END_PARSE_FLAGS();
|
||||
|
||||
if (has_action) {
|
||||
|
Loading…
Reference in New Issue
Block a user