From 16ab28f2307f2ee93d5ba16c80f6234cb08e0252 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 5 Mar 2021 20:06:37 +0300 Subject: [PATCH] Allow to send speaking actions in read-only chats. --- td/telegram/MessagesManager.cpp | 35 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index b58fb794f..522ab3349 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -3825,9 +3825,9 @@ class SetTypingQuery : public Td::ResultHandler { explicit SetTypingQuery(Promise &&promise) : promise_(std::move(promise)) { } - NetQueryRef send(DialogId dialog_id, MessageId message_id, tl_object_ptr &&action) { + NetQueryRef send(DialogId dialog_id, tl_object_ptr &&input_peer, MessageId message_id, + tl_object_ptr &&action) { dialog_id_ = dialog_id; - auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Write); CHECK(input_peer != nullptr); int32 flags = 0; @@ -30388,16 +30388,26 @@ void MessagesManager::send_dialog_action(DialogId dialog_id, MessageId top_threa return promise.set_error(Status::Error(5, "Invalid message thread specified")); } - auto can_send_status = can_send_message(dialog_id); - if (can_send_status.is_error()) { - if (td_->auth_manager_->is_bot()) { - return promise.set_error(can_send_status.move_as_error()); + tl_object_ptr input_peer; + if (action == DialogAction::get_speaking_action()) { + input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Read); + if (input_peer == nullptr) { + return promise.set_error(Status::Error(400, "Have no access to the chat")); + } + } else { + auto can_send_status = can_send_message(dialog_id); + if (can_send_status.is_error()) { + if (td_->auth_manager_->is_bot()) { + return promise.set_error(can_send_status.move_as_error()); + } + return promise.set_value(Unit()); } - return promise.set_value(Unit()); - } - if (is_dialog_action_unneeded(dialog_id)) { - return promise.set_value(Unit()); + if (is_dialog_action_unneeded(dialog_id)) { + return promise.set_value(Unit()); + } + + input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write); } if (dialog_id.get_type() == DialogType::SecretChat) { @@ -30412,8 +30422,9 @@ void MessagesManager::send_dialog_action(DialogId dialog_id, MessageId top_threa LOG(INFO) << "Cancel previous send chat action query"; cancel_query(query_ref); } - query_ref = td_->create_handler(std::move(promise)) - ->send(dialog_id, top_thread_message_id, action.get_input_send_message_action()); + query_ref = + td_->create_handler(std::move(promise)) + ->send(dialog_id, std::move(input_peer), top_thread_message_id, action.get_input_send_message_action()); } void MessagesManager::on_send_dialog_action_timeout(DialogId dialog_id) {