From ecc97d06b9aa647d215625c3c314cb155139df8a Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 20 Sep 2020 04:30:46 +0300 Subject: [PATCH] Fix chat blocking. GitOrigin-RevId: c55076283c272019e0eb2908aab71efc09ad190a --- td/generate/scheme/td_api.tl | 2 +- td/telegram/AccessRights.h | 2 +- td/telegram/ContactsManager.cpp | 12 ++++++++++++ td/telegram/MessagesManager.cpp | 20 +++++++------------- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 1eea81343..b820ab93b 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4005,7 +4005,7 @@ setChatNotificationSettings chat_id:int53 notification_settings:chatNotification //@description Changes the marked as unread state of a chat @chat_id Chat identifier @is_marked_as_unread New value of is_marked_as_unread toggleChatIsMarkedAsUnread chat_id:int53 is_marked_as_unread:Bool = Ok; -//@description Changes the block state of a chat @chat_id Chat identifier @is_blocked New value of is_blocked +//@description Changes the block state of a chat. Currently, only private chats and supergroups can be blocked @chat_id Chat identifier @is_blocked New value of is_blocked toggleChatIsBlocked chat_id:int53 is_blocked:Bool = Ok; //@description Changes the value of the default disable_notification parameter, used when a message is sent to a chat @chat_id Chat identifier @default_disable_notification New value of default_disable_notification diff --git a/td/telegram/AccessRights.h b/td/telegram/AccessRights.h index 029cea6d0..bc6fe8131 100644 --- a/td/telegram/AccessRights.h +++ b/td/telegram/AccessRights.h @@ -10,6 +10,6 @@ namespace td { -enum class AccessRights : int32 { Read, Edit, Write }; +enum class AccessRights : int32 { Know, Read, Edit, Write }; } // namespace td diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index ed3510719..e84d15e72 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -3975,6 +3975,9 @@ bool ContactsManager::have_input_peer_user(const User *u, AccessRights access_ri if (u->access_hash == -1 || u->is_min_access_hash) { return false; } + if (access_rights == AccessRights::Know) { + return true; + } if (access_rights == AccessRights::Read) { return true; } @@ -4005,6 +4008,9 @@ bool ContactsManager::have_input_peer_chat(const Chat *c, AccessRights access_ri if (c == nullptr) { return false; } + if (access_rights == AccessRights::Know) { + return true; + } if (access_rights == AccessRights::Read) { return true; } @@ -4047,6 +4053,9 @@ bool ContactsManager::have_input_peer_channel(const Channel *c, ChannelId channe if (c == nullptr) { return false; } + if (access_rights == AccessRights::Know) { + return true; + } if (c->status.is_creator()) { return true; } @@ -4090,6 +4099,9 @@ bool ContactsManager::have_input_encrypted_peer(const SecretChat *secret_chat, A if (secret_chat == nullptr) { return false; } + if (access_rights == AccessRights::Know) { + return true; + } if (access_rights == AccessRights::Read) { return true; } diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index b81fa04af..934f989c2 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -1421,7 +1421,7 @@ class ToggleDialogIsBlockedQuery : public Td::ResultHandler { dialog_id_ = dialog_id; is_blocked_ = is_blocked; - auto input_peer = MessagesManager::get_input_peer_force(dialog_id); + auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Know); CHECK(input_peer != nullptr && input_peer->get_id() != telegram_api::inputPeerEmpty::ID); if (is_blocked) { send_query(G()->net_query_creator().create(telegram_api::contacts_block(std::move(input_peer)))); @@ -5603,18 +5603,12 @@ tl_object_ptr MessagesManager::get_input_message(Mes tl_object_ptr MessagesManager::get_input_peer(DialogId dialog_id, AccessRights access_rights) const { switch (dialog_id.get_type()) { - case DialogType::User: { - UserId user_id = dialog_id.get_user_id(); - return td_->contacts_manager_->get_input_peer_user(user_id, access_rights); - } - case DialogType::Chat: { - ChatId chat_id = dialog_id.get_chat_id(); - return td_->contacts_manager_->get_input_peer_chat(chat_id, access_rights); - } - case DialogType::Channel: { - ChannelId channel_id = dialog_id.get_channel_id(); - return td_->contacts_manager_->get_input_peer_channel(channel_id, access_rights); - } + case DialogType::User: + return td_->contacts_manager_->get_input_peer_user(dialog_id.get_user_id(), access_rights); + case DialogType::Chat: + return td_->contacts_manager_->get_input_peer_chat(dialog_id.get_chat_id(), access_rights); + case DialogType::Channel: + return td_->contacts_manager_->get_input_peer_channel(dialog_id.get_channel_id(), access_rights); case DialogType::SecretChat: return nullptr; case DialogType::None: