From 9a9ffa6794ba65e2e3347e532cfc4bdcc386c03b Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 12 Feb 2024 18:48:14 +0300 Subject: [PATCH] Add and use can_change_info_and_settings_as_administrator. --- td/telegram/BackgroundManager.cpp | 4 +++- td/telegram/ContactsManager.cpp | 12 ++++++------ td/telegram/DialogParticipant.h | 4 ++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/td/telegram/BackgroundManager.cpp b/td/telegram/BackgroundManager.cpp index c80e1f3d8..1b40cd7c4 100644 --- a/td/telegram/BackgroundManager.cpp +++ b/td/telegram/BackgroundManager.cpp @@ -755,7 +755,9 @@ Result BackgroundManager::get_background_dialog(DialogId dialog_id) { case DialogType::Chat: return Status::Error(400, "Can't change background in the chat"); case DialogType::Channel: { - if (!td_->contacts_manager_->get_channel_status(dialog_id.get_channel_id()).can_change_info_and_settings()) { + auto channel_id = dialog_id.get_channel_id(); + if (!td_->contacts_manager_->get_channel_permissions(channel_id) + .can_change_info_and_settings_as_administrator()) { return Status::Error(400, "Not enough rights in the chat"); } return dialog_id; diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index bfc2b77cc..65759acdf 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -7319,7 +7319,7 @@ void ContactsManager::set_channel_accent_color(ChannelId channel_id, AccentColor if (c->is_megagroup) { return promise.set_error(Status::Error(400, "Accent color can be changed only in channel chats")); } - if (!get_channel_status(c).can_change_info_and_settings()) { + if (!get_channel_permissions(channel_id, c).can_change_info_and_settings_as_administrator()) { return promise.set_error(Status::Error(400, "Not enough rights in the channel")); } @@ -7334,7 +7334,7 @@ void ContactsManager::set_channel_profile_accent_color(ChannelId channel_id, Acc if (c == nullptr) { return promise.set_error(Status::Error(400, "Chat not found")); } - if (!get_channel_status(c).can_change_info_and_settings()) { + if (!get_channel_permissions(channel_id, c).can_change_info_and_settings_as_administrator()) { return promise.set_error(Status::Error(400, "Not enough rights in the chat")); } @@ -7348,7 +7348,7 @@ void ContactsManager::set_channel_emoji_status(ChannelId channel_id, const Emoji if (c == nullptr) { return promise.set_error(Status::Error(400, "Chat not found")); } - if (!get_channel_status(c).can_change_info_and_settings()) { + if (!get_channel_permissions(channel_id, c).can_change_info_and_settings_as_administrator()) { return promise.set_error(Status::Error(400, "Not enough rights in the chat")); } @@ -7366,7 +7366,7 @@ void ContactsManager::set_channel_sticker_set(ChannelId channel_id, StickerSetId if (!c->is_megagroup) { return promise.set_error(Status::Error(400, "Chat sticker set can be set only for supergroups")); } - if (!get_channel_status(c).can_change_info_and_settings()) { + if (!get_channel_permissions(channel_id, c).can_change_info_and_settings_as_administrator()) { return promise.set_error(Status::Error(400, "Not enough rights to change supergroup sticker set")); } @@ -7398,7 +7398,7 @@ void ContactsManager::set_channel_emoji_sticker_set(ChannelId channel_id, Sticke if (!c->is_megagroup) { return promise.set_error(Status::Error(400, "Cuctom emoji sticker set can be set only for supergroups")); } - if (!get_channel_status(c).can_change_info_and_settings()) { + if (!get_channel_permissions(channel_id, c).can_change_info_and_settings_as_administrator()) { return promise.set_error( Status::Error(400, "Not enough rights to change custom emoji sticker set in the supergroup")); } @@ -7676,7 +7676,7 @@ void ContactsManager::set_channel_discussion_group(DialogId dialog_id, DialogId if (c->is_megagroup) { return promise.set_error(Status::Error(400, "Chat is not a channel")); } - if (!c->status.is_administrator() || !c->status.can_change_info_and_settings()) { + if (!c->status.can_change_info_and_settings_as_administrator()) { return promise.set_error(Status::Error(400, "Not enough rights in the channel")); } diff --git a/td/telegram/DialogParticipant.h b/td/telegram/DialogParticipant.h index 8e1ab4913..5f96cdce2 100644 --- a/td/telegram/DialogParticipant.h +++ b/td/telegram/DialogParticipant.h @@ -389,6 +389,10 @@ class DialogParticipantStatus { return get_administrator_rights().can_manage_dialog(); } + bool can_change_info_and_settings_as_administrator() const { + return get_administrator_rights().can_change_info_and_settings(); + } + bool can_change_info_and_settings() const { return get_administrator_rights().can_change_info_and_settings() || get_restricted_rights().can_change_info_and_settings();