Add and use can_change_info_and_settings_as_administrator.

This commit is contained in:
levlam 2024-02-12 18:48:14 +03:00
parent 9e32ab8ad1
commit 9a9ffa6794
3 changed files with 13 additions and 7 deletions

View File

@ -755,7 +755,9 @@ Result<DialogId> 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;

View File

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

View File

@ -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();