Allow to send speaking actions in read-only chats.

This commit is contained in:
levlam 2021-03-05 20:06:37 +03:00
parent 8ede5f736f
commit 16ab28f230

View File

@ -3825,9 +3825,9 @@ class SetTypingQuery : public Td::ResultHandler {
explicit SetTypingQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) { explicit SetTypingQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
} }
NetQueryRef send(DialogId dialog_id, MessageId message_id, tl_object_ptr<telegram_api::SendMessageAction> &&action) { NetQueryRef send(DialogId dialog_id, tl_object_ptr<telegram_api::InputPeer> &&input_peer, MessageId message_id,
tl_object_ptr<telegram_api::SendMessageAction> &&action) {
dialog_id_ = dialog_id; dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
CHECK(input_peer != nullptr); CHECK(input_peer != nullptr);
int32 flags = 0; int32 flags = 0;
@ -30388,6 +30388,13 @@ void MessagesManager::send_dialog_action(DialogId dialog_id, MessageId top_threa
return promise.set_error(Status::Error(5, "Invalid message thread specified")); return promise.set_error(Status::Error(5, "Invalid message thread specified"));
} }
tl_object_ptr<telegram_api::InputPeer> 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); auto can_send_status = can_send_message(dialog_id);
if (can_send_status.is_error()) { if (can_send_status.is_error()) {
if (td_->auth_manager_->is_bot()) { if (td_->auth_manager_->is_bot()) {
@ -30400,6 +30407,9 @@ void MessagesManager::send_dialog_action(DialogId dialog_id, MessageId top_threa
return promise.set_value(Unit()); return promise.set_value(Unit());
} }
input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
}
if (dialog_id.get_type() == DialogType::SecretChat) { if (dialog_id.get_type() == DialogType::SecretChat) {
send_closure(G()->secret_chats_manager(), &SecretChatsManager::send_message_action, dialog_id.get_secret_chat_id(), send_closure(G()->secret_chats_manager(), &SecretChatsManager::send_message_action, dialog_id.get_secret_chat_id(),
action.get_secret_input_send_message_action()); action.get_secret_input_send_message_action());
@ -30412,8 +30422,9 @@ void MessagesManager::send_dialog_action(DialogId dialog_id, MessageId top_threa
LOG(INFO) << "Cancel previous send chat action query"; LOG(INFO) << "Cancel previous send chat action query";
cancel_query(query_ref); cancel_query(query_ref);
} }
query_ref = td_->create_handler<SetTypingQuery>(std::move(promise)) query_ref =
->send(dialog_id, top_thread_message_id, action.get_input_send_message_action()); td_->create_handler<SetTypingQuery>(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) { void MessagesManager::on_send_dialog_action_timeout(DialogId dialog_id) {