Ignore restrictions by supergroup boosters.

This commit is contained in:
levlam 2024-02-08 23:30:41 +03:00
parent 353c809298
commit 0238a3da42
4 changed files with 32 additions and 21 deletions

View File

@ -7321,7 +7321,7 @@ void ContactsManager::set_channel_sticker_set(ChannelId channel_id, StickerSetId
if (!c->is_megagroup) { if (!c->is_megagroup) {
return promise.set_error(Status::Error(400, "Chat sticker set can be set only for supergroups")); return promise.set_error(Status::Error(400, "Chat sticker set can be set only for supergroups"));
} }
if (!get_channel_permissions(c).can_change_info_and_settings()) { if (!get_channel_permissions(channel_id, c).can_change_info_and_settings()) {
return promise.set_error(Status::Error(400, "Not enough rights to change supergroup sticker set")); return promise.set_error(Status::Error(400, "Not enough rights to change supergroup sticker set"));
} }
@ -7353,7 +7353,7 @@ void ContactsManager::set_channel_emoji_sticker_set(ChannelId channel_id, Sticke
if (!c->is_megagroup) { if (!c->is_megagroup) {
return promise.set_error(Status::Error(400, "Cuctom emoji sticker set can be set only for supergroups")); return promise.set_error(Status::Error(400, "Cuctom emoji sticker set can be set only for supergroups"));
} }
if (!get_channel_permissions(c).can_change_info_and_settings()) { if (!get_channel_permissions(channel_id, c).can_change_info_and_settings()) {
return promise.set_error( return promise.set_error(
Status::Error(400, "Not enough rights to change custom emoji sticker set in the supergroup")); Status::Error(400, "Not enough rights to change custom emoji sticker set in the supergroup"));
} }
@ -7380,7 +7380,7 @@ void ContactsManager::toggle_channel_sign_messages(ChannelId channel_id, bool si
if (get_channel_type(c) == ChannelType::Megagroup) { if (get_channel_type(c) == ChannelType::Megagroup) {
return promise.set_error(Status::Error(400, "Message signatures can't be toggled in supergroups")); return promise.set_error(Status::Error(400, "Message signatures can't be toggled in supergroups"));
} }
if (!get_channel_permissions(c).can_change_info_and_settings()) { if (!get_channel_permissions(channel_id, c).can_change_info_and_settings()) {
return promise.set_error(Status::Error(400, "Not enough rights to toggle channel sign messages")); return promise.set_error(Status::Error(400, "Not enough rights to toggle channel sign messages"));
} }
@ -7395,7 +7395,7 @@ void ContactsManager::toggle_channel_join_to_send(ChannelId channel_id, bool joi
if (get_channel_type(c) == ChannelType::Broadcast || c->is_gigagroup) { if (get_channel_type(c) == ChannelType::Broadcast || c->is_gigagroup) {
return promise.set_error(Status::Error(400, "The method can be called only for ordinary supergroups")); return promise.set_error(Status::Error(400, "The method can be called only for ordinary supergroups"));
} }
if (!get_channel_permissions(c).can_restrict_members()) { if (!get_channel_status(c).can_restrict_members()) {
return promise.set_error(Status::Error(400, "Not enough rights")); return promise.set_error(Status::Error(400, "Not enough rights"));
} }
@ -7410,7 +7410,7 @@ void ContactsManager::toggle_channel_join_request(ChannelId channel_id, bool joi
if (get_channel_type(c) == ChannelType::Broadcast || c->is_gigagroup) { if (get_channel_type(c) == ChannelType::Broadcast || c->is_gigagroup) {
return promise.set_error(Status::Error(400, "The method can be called only for ordinary supergroups")); return promise.set_error(Status::Error(400, "The method can be called only for ordinary supergroups"));
} }
if (!get_channel_permissions(c).can_restrict_members()) { if (!get_channel_status(c).can_restrict_members()) {
return promise.set_error(Status::Error(400, "Not enough rights")); return promise.set_error(Status::Error(400, "Not enough rights"));
} }
@ -7423,7 +7423,7 @@ void ContactsManager::toggle_channel_is_all_history_available(ChannelId channel_
if (c == nullptr) { if (c == nullptr) {
return promise.set_error(Status::Error(400, "Supergroup not found")); return promise.set_error(Status::Error(400, "Supergroup not found"));
} }
if (!get_channel_permissions(c).can_change_info_and_settings()) { if (!get_channel_permissions(channel_id, c).can_change_info_and_settings()) {
return promise.set_error(Status::Error(400, "Not enough rights to toggle all supergroup history availability")); return promise.set_error(Status::Error(400, "Not enough rights to toggle all supergroup history availability"));
} }
if (get_channel_type(c) != ChannelType::Megagroup) { if (get_channel_type(c) != ChannelType::Megagroup) {
@ -7459,7 +7459,7 @@ Status ContactsManager::can_hide_channel_participants(ChannelId channel_id, cons
if (c == nullptr) { if (c == nullptr) {
return Status::Error(400, "Supergroup not found"); return Status::Error(400, "Supergroup not found");
} }
if (!get_channel_permissions(c).can_restrict_members()) { if (!get_channel_status(c).can_restrict_members()) {
return Status::Error(400, "Not enough rights to hide group members"); return Status::Error(400, "Not enough rights to hide group members");
} }
if (get_channel_type(c) != ChannelType::Megagroup) { if (get_channel_type(c) != ChannelType::Megagroup) {
@ -7504,7 +7504,7 @@ Status ContactsManager::can_toggle_channel_aggressive_anti_spam(ChannelId channe
if (c == nullptr) { if (c == nullptr) {
return Status::Error(400, "Supergroup not found"); return Status::Error(400, "Supergroup not found");
} }
if (!get_channel_permissions(c).can_delete_messages()) { if (!get_channel_status(c).can_delete_messages()) {
return Status::Error(400, "Not enough rights to enable aggressive anti-spam checks"); return Status::Error(400, "Not enough rights to enable aggressive anti-spam checks");
} }
if (get_channel_type(c) != ChannelType::Megagroup) { if (get_channel_type(c) != ChannelType::Megagroup) {
@ -7543,7 +7543,7 @@ void ContactsManager::toggle_channel_is_forum(ChannelId channel_id, bool is_foru
if (c->is_forum == is_forum) { if (c->is_forum == is_forum) {
return promise.set_value(Unit()); return promise.set_value(Unit());
} }
if (!get_channel_permissions(c).is_creator()) { if (!get_channel_status(c).is_creator()) {
return promise.set_error(Status::Error(400, "Not enough rights to convert the group to a forum")); return promise.set_error(Status::Error(400, "Not enough rights to convert the group to a forum"));
} }
if (get_channel_type(c) != ChannelType::Megagroup) { if (get_channel_type(c) != ChannelType::Megagroup) {
@ -7558,7 +7558,7 @@ void ContactsManager::convert_channel_to_gigagroup(ChannelId channel_id, Promise
if (c == nullptr) { if (c == nullptr) {
return promise.set_error(Status::Error(400, "Supergroup not found")); return promise.set_error(Status::Error(400, "Supergroup not found"));
} }
if (!get_channel_permissions(c).is_creator()) { if (!get_channel_status(c).is_creator()) {
return promise.set_error(Status::Error(400, "Not enough rights to convert group to broadcast group")); return promise.set_error(Status::Error(400, "Not enough rights to convert group to broadcast group"));
} }
if (get_channel_type(c) != ChannelType::Megagroup) { if (get_channel_type(c) != ChannelType::Megagroup) {
@ -7577,7 +7577,7 @@ void ContactsManager::set_channel_description(ChannelId channel_id, const string
if (c == nullptr) { if (c == nullptr) {
return promise.set_error(Status::Error(400, "Chat info not found")); return promise.set_error(Status::Error(400, "Chat info not found"));
} }
if (!get_channel_permissions(c).can_change_info_and_settings()) { if (!get_channel_permissions(channel_id, c).can_change_info_and_settings()) {
return promise.set_error(Status::Error(400, "Not enough rights to set chat description")); return promise.set_error(Status::Error(400, "Not enough rights to set chat description"));
} }
@ -7711,7 +7711,7 @@ void ContactsManager::set_channel_slow_mode_delay(DialogId dialog_id, int32 slow
if (!c->is_megagroup) { if (!c->is_megagroup) {
return promise.set_error(Status::Error(400, "Chat is not a supergroup")); return promise.set_error(Status::Error(400, "Chat is not a supergroup"));
} }
if (!get_channel_permissions(c).can_restrict_members()) { if (!get_channel_status(c).can_restrict_members()) {
return promise.set_error(Status::Error(400, "Not enough rights in the supergroup")); return promise.set_error(Status::Error(400, "Not enough rights in the supergroup"));
} }
@ -16511,7 +16511,7 @@ DialogParticipantStatus ContactsManager::get_chat_permissions(const Chat *c) con
if (!c->is_active) { if (!c->is_active) {
return DialogParticipantStatus::Banned(0); return DialogParticipantStatus::Banned(0);
} }
return c->status.apply_restrictions(c->default_permissions, td_->auth_manager_->is_bot()); return c->status.apply_restrictions(c->default_permissions, false, td_->auth_manager_->is_bot());
} }
bool ContactsManager::is_appointed_chat_administrator(ChatId chat_id) const { bool ContactsManager::is_appointed_chat_administrator(ChatId chat_id) const {
@ -16591,12 +16591,20 @@ DialogParticipantStatus ContactsManager::get_channel_permissions(ChannelId chann
if (c == nullptr) { if (c == nullptr) {
return DialogParticipantStatus::Banned(0); return DialogParticipantStatus::Banned(0);
} }
return get_channel_permissions(c); return get_channel_permissions(channel_id, c);
} }
DialogParticipantStatus ContactsManager::get_channel_permissions(const Channel *c) const { DialogParticipantStatus ContactsManager::get_channel_permissions(ChannelId channel_id, const Channel *c) const {
c->status.update_restrictions(); c->status.update_restrictions();
return c->status.apply_restrictions(c->default_permissions, td_->auth_manager_->is_bot()); bool is_booster = false;
if (!td_->auth_manager_->is_bot() && c->is_megagroup) {
auto channel_full = get_channel_full_const(channel_id);
if (channel_full == nullptr || (channel_full->unrestrict_boost_count > 0 &&
channel_full->boost_count >= channel_full->unrestrict_boost_count)) {
is_booster = true;
}
}
return c->status.apply_restrictions(c->default_permissions, is_booster, td_->auth_manager_->is_bot());
} }
int32 ContactsManager::get_channel_participant_count(ChannelId channel_id) const { int32 ContactsManager::get_channel_participant_count(ChannelId channel_id) const {

View File

@ -1395,7 +1395,7 @@ class ContactsManager final : public Actor {
static ChannelType get_channel_type(const Channel *c); static ChannelType get_channel_type(const Channel *c);
static DialogParticipantStatus get_channel_status(const Channel *c); static DialogParticipantStatus get_channel_status(const Channel *c);
DialogParticipantStatus get_channel_permissions(const Channel *c) const; DialogParticipantStatus get_channel_permissions(ChannelId channel_id, const Channel *c) const;
static bool get_channel_sign_messages(const Channel *c); static bool get_channel_sign_messages(const Channel *c);
static bool get_channel_has_linked_channel(const Channel *c); static bool get_channel_has_linked_channel(const Channel *c);
static bool get_channel_can_be_deleted(const Channel *c); static bool get_channel_can_be_deleted(const Channel *c);

View File

@ -553,7 +553,7 @@ tl_object_ptr<telegram_api::chatBannedRights> DialogParticipantStatus::get_chat_
} }
DialogParticipantStatus DialogParticipantStatus::apply_restrictions(RestrictedRights default_restrictions, DialogParticipantStatus DialogParticipantStatus::apply_restrictions(RestrictedRights default_restrictions,
bool is_bot) const { bool is_booster, bool is_bot) const {
auto flags = flags_; auto flags = flags_;
switch (type_) { switch (type_) {
case Type::Creator: case Type::Creator:
@ -569,9 +569,12 @@ DialogParticipantStatus DialogParticipantStatus::apply_restrictions(RestrictedRi
case Type::Member: case Type::Member:
case Type::Restricted: case Type::Restricted:
case Type::Left: case Type::Left:
// members and restricted are affected by default restrictions if (!is_booster) {
flags &= (~RestrictedRights::ALL_RESTRICTED_RIGHTS) | default_restrictions.flags_; // members and restricted are affected by default restrictions unless they are supergroup boosters
flags &= (~RestrictedRights::ALL_RESTRICTED_RIGHTS) | default_restrictions.flags_;
}
if (is_bot) { if (is_bot) {
// bots must be explicitly granted administrator rights to use them
flags &= ~RestrictedRights::ALL_ADMIN_PERMISSION_RIGHTS; flags &= ~RestrictedRights::ALL_ADMIN_PERMISSION_RIGHTS;
} }
break; break;

View File

@ -374,7 +374,7 @@ class DialogParticipantStatus {
RestrictedRights get_effective_restricted_rights() const; RestrictedRights get_effective_restricted_rights() const;
DialogParticipantStatus apply_restrictions(RestrictedRights default_restrictions, bool is_bot) const; DialogParticipantStatus apply_restrictions(RestrictedRights default_restrictions, bool is_booster, bool is_bot) const;
tl_object_ptr<td_api::ChatMemberStatus> get_chat_member_status_object() const; tl_object_ptr<td_api::ChatMemberStatus> get_chat_member_status_object() const;