Fix chat blocking.

GitOrigin-RevId: c55076283c272019e0eb2908aab71efc09ad190a
This commit is contained in:
levlam 2020-09-20 04:30:46 +03:00
parent 446ba8d406
commit ecc97d06b9
4 changed files with 21 additions and 15 deletions

View File

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

View File

@ -10,6 +10,6 @@
namespace td {
enum class AccessRights : int32 { Read, Edit, Write };
enum class AccessRights : int32 { Know, Read, Edit, Write };
} // namespace td

View File

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

View File

@ -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<telegram_api::InputMessage> MessagesManager::get_input_message(Mes
tl_object_ptr<telegram_api::InputPeer> 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: