diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 979449b33..c3bb6e6b5 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -9155,11 +9155,11 @@ DialogParticipantStatus ContactsManager::get_chat_permissions(ChatId chat_id) co return get_chat_permissions(c); } -DialogParticipantStatus ContactsManager::get_chat_permissions(const Chat *c) { +DialogParticipantStatus ContactsManager::get_chat_permissions(const Chat *c) const { if (!c->is_active) { return DialogParticipantStatus::Banned(0); } - return c->status.apply_restrictions(c->default_permissions); + return c->status.apply_restrictions(c->default_permissions, td_->auth_manager_->is_bot()); } bool ContactsManager::is_appointed_chat_administrator(ChatId chat_id) const { @@ -9223,13 +9223,13 @@ DialogParticipantStatus ContactsManager::get_channel_permissions(ChannelId chann return get_channel_permissions(c); } -DialogParticipantStatus ContactsManager::get_channel_permissions(const Channel *c) { +DialogParticipantStatus ContactsManager::get_channel_permissions(const Channel *c) const { c->status.update_restrictions(); if (!c->is_megagroup) { // there is no restrictions in broadcast channels return c->status; } - return c->status.apply_restrictions(c->default_permissions); + return c->status.apply_restrictions(c->default_permissions, td_->auth_manager_->is_bot()); } int32 ContactsManager::get_channel_participant_count(ChannelId channel_id) const { diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 6b5bedfe5..c2bc54961 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -857,11 +857,11 @@ class ContactsManager : public Actor { SecretChat *add_secret_chat(SecretChatId secret_chat_id); static DialogParticipantStatus get_chat_status(const Chat *c); - static DialogParticipantStatus get_chat_permissions(const Chat *c); + DialogParticipantStatus get_chat_permissions(const Chat *c) const; static ChannelType get_channel_type(const Channel *c); static DialogParticipantStatus get_channel_status(const Channel *c); - static DialogParticipantStatus get_channel_permissions(const Channel *c); + DialogParticipantStatus get_channel_permissions(const Channel *c) const; static bool get_channel_sign_messages(const Channel *c); void set_my_id(UserId my_id); diff --git a/td/telegram/DialogParticipant.cpp b/td/telegram/DialogParticipant.cpp index 1c7bdf72e..7a0e5a985 100644 --- a/td/telegram/DialogParticipant.cpp +++ b/td/telegram/DialogParticipant.cpp @@ -201,7 +201,8 @@ tl_object_ptr DialogParticipantStatus::get_chat_ false /*ignored*/, until_date_); } -DialogParticipantStatus DialogParticipantStatus::apply_restrictions(RestrictedRights default_restrictions) const { +DialogParticipantStatus DialogParticipantStatus::apply_restrictions(RestrictedRights default_restrictions, + bool is_bot) const { auto flags = flags_; switch (type_) { case Type::Creator: @@ -210,13 +211,18 @@ DialogParticipantStatus DialogParticipantStatus::apply_restrictions(RestrictedRi case Type::Administrator: // administrators aren't affected by restrictions, but if everyone can invite users, // pin messages or change info, they also can do that - flags |= default_restrictions.flags_ & ALL_ADMIN_PERMISSION_RIGHTS; + if (!is_bot) { + flags |= default_restrictions.flags_ & ALL_ADMIN_PERMISSION_RIGHTS; + } break; case Type::Member: case Type::Restricted: case Type::Left: // members and restricted are affected by default restrictions flags &= ~ALL_PERMISSION_RIGHTS | default_restrictions.flags_; + if (is_bot) { + flags &= ~ALL_ADMIN_PERMISSION_RIGHTS; + } break; case Type::Banned: // banned can do nothing, even restirctions allows them to do that diff --git a/td/telegram/DialogParticipant.h b/td/telegram/DialogParticipant.h index a881d56a8..545f0bf36 100644 --- a/td/telegram/DialogParticipant.h +++ b/td/telegram/DialogParticipant.h @@ -193,7 +193,7 @@ class DialogParticipantStatus { RestrictedRights get_restricted_rights() const; - DialogParticipantStatus apply_restrictions(RestrictedRights default_restrictions) const; + DialogParticipantStatus apply_restrictions(RestrictedRights default_restrictions, bool is_bot) const; tl_object_ptr get_chat_member_status_object() const;