Remove duplicate administrator flags from DialogParticipantStatus.
This commit is contained in:
parent
d97d20a420
commit
07b4f6c16d
@ -23,15 +23,61 @@ AdministratorRights::AdministratorRights(bool can_manage_dialog, bool can_change
|
||||
bool can_restrict_members, bool can_pin_messages, bool can_promote_members,
|
||||
bool can_manage_calls) {
|
||||
flags_ = (static_cast<uint32>(can_manage_dialog) * CAN_MANAGE_DIALOG) |
|
||||
(static_cast<uint32>(can_change_info) * CAN_CHANGE_INFO_AND_SETTINGS_ADMIN) |
|
||||
(static_cast<uint32>(can_change_info) * CAN_CHANGE_INFO_AND_SETTINGS) |
|
||||
(static_cast<uint32>(can_post_messages) * CAN_POST_MESSAGES) |
|
||||
(static_cast<uint32>(can_edit_messages) * CAN_EDIT_MESSAGES) |
|
||||
(static_cast<uint32>(can_delete_messages) * CAN_DELETE_MESSAGES) |
|
||||
(static_cast<uint32>(can_invite_users) * CAN_INVITE_USERS_ADMIN) |
|
||||
(static_cast<uint32>(can_invite_users) * CAN_INVITE_USERS) |
|
||||
(static_cast<uint32>(can_restrict_members) * CAN_RESTRICT_MEMBERS) |
|
||||
(static_cast<uint32>(can_pin_messages) * CAN_PIN_MESSAGES_ADMIN) |
|
||||
(static_cast<uint32>(can_pin_messages) * CAN_PIN_MESSAGES) |
|
||||
(static_cast<uint32>(can_promote_members) * CAN_PROMOTE_MEMBERS) |
|
||||
(static_cast<uint32>(can_manage_calls) * CAN_MANAGE_CALLS);
|
||||
if (flags_ != 0) {
|
||||
flags_ |= CAN_MANAGE_DIALOG;
|
||||
}
|
||||
}
|
||||
|
||||
telegram_api::object_ptr<telegram_api::chatAdminRights> AdministratorRights::get_chat_admin_rights(
|
||||
bool is_anonymous) const {
|
||||
int32 flags = 0;
|
||||
if ((flags_ & CAN_CHANGE_INFO_AND_SETTINGS) != 0) {
|
||||
flags |= telegram_api::chatAdminRights::CHANGE_INFO_MASK;
|
||||
}
|
||||
if (can_post_messages()) {
|
||||
flags |= telegram_api::chatAdminRights::POST_MESSAGES_MASK;
|
||||
}
|
||||
if (can_edit_messages()) {
|
||||
flags |= telegram_api::chatAdminRights::EDIT_MESSAGES_MASK;
|
||||
}
|
||||
if (can_delete_messages()) {
|
||||
flags |= telegram_api::chatAdminRights::DELETE_MESSAGES_MASK;
|
||||
}
|
||||
if ((flags_ & CAN_INVITE_USERS) != 0) {
|
||||
flags |= telegram_api::chatAdminRights::INVITE_USERS_MASK;
|
||||
}
|
||||
if (can_restrict_members()) {
|
||||
flags |= telegram_api::chatAdminRights::BAN_USERS_MASK;
|
||||
}
|
||||
if ((flags_ & CAN_PIN_MESSAGES) != 0) {
|
||||
flags |= telegram_api::chatAdminRights::PIN_MESSAGES_MASK;
|
||||
}
|
||||
if (can_promote_members()) {
|
||||
flags |= telegram_api::chatAdminRights::ADD_ADMINS_MASK;
|
||||
}
|
||||
if (can_manage_calls()) {
|
||||
flags |= telegram_api::chatAdminRights::MANAGE_CALL_MASK;
|
||||
}
|
||||
if (can_manage_dialog()) {
|
||||
flags |= telegram_api::chatAdminRights::OTHER_MASK;
|
||||
}
|
||||
|
||||
if (is_anonymous) {
|
||||
flags |= telegram_api::chatAdminRights::ANONYMOUS_MASK;
|
||||
}
|
||||
|
||||
return telegram_api::make_object<telegram_api::chatAdminRights>(
|
||||
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
|
||||
false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/);
|
||||
}
|
||||
|
||||
bool operator==(const AdministratorRights &lhs, const AdministratorRights &rhs) {
|
||||
@ -203,8 +249,8 @@ int32 DialogParticipantStatus::fix_until_date(int32 date) {
|
||||
|
||||
DialogParticipantStatus DialogParticipantStatus::Creator(bool is_member, bool is_anonymous, string rank) {
|
||||
return DialogParticipantStatus(Type::Creator,
|
||||
ALL_ADMINISTRATOR_RIGHTS | ALL_PERMISSION_RIGHTS | (is_member ? IS_MEMBER : 0) |
|
||||
(is_anonymous ? IS_ANONYMOUS : 0),
|
||||
AdministratorRights::ALL_ADMINISTRATOR_RIGHTS | ALL_PERMISSION_RIGHTS |
|
||||
(is_member ? IS_MEMBER : 0) | (is_anonymous ? IS_ANONYMOUS : 0),
|
||||
0, std::move(rank));
|
||||
}
|
||||
|
||||
@ -217,13 +263,14 @@ DialogParticipantStatus DialogParticipantStatus::Administrator(bool is_anonymous
|
||||
uint32 flags = AdministratorRights(can_manage_dialog, can_change_info, can_post_messages, can_edit_messages,
|
||||
can_delete_messages, can_invite_users, can_restrict_members, can_pin_messages,
|
||||
can_promote_members, can_manage_calls)
|
||||
.flags_ |
|
||||
(static_cast<uint32>(can_be_edited) * CAN_BE_EDITED) |
|
||||
(static_cast<uint32>(is_anonymous) * IS_ANONYMOUS);
|
||||
if (flags == 0 || flags == CAN_BE_EDITED) {
|
||||
.flags_;
|
||||
if (is_anonymous) {
|
||||
flags |= IS_ANONYMOUS | AdministratorRights::CAN_MANAGE_DIALOG;
|
||||
}
|
||||
if (flags == 0) {
|
||||
return Member();
|
||||
}
|
||||
flags |= CAN_MANAGE_DIALOG;
|
||||
flags = flags | (static_cast<uint32>(can_be_edited) * CAN_BE_EDITED);
|
||||
return DialogParticipantStatus(Type::Administrator, IS_MEMBER | ALL_RESTRICTED_RIGHTS | flags, 0, std::move(rank));
|
||||
}
|
||||
|
||||
@ -297,45 +344,7 @@ tl_object_ptr<td_api::ChatMemberStatus> DialogParticipantStatus::get_chat_member
|
||||
}
|
||||
|
||||
tl_object_ptr<telegram_api::chatAdminRights> DialogParticipantStatus::get_chat_admin_rights() const {
|
||||
int32 flags = 0;
|
||||
if ((flags_ & CAN_CHANGE_INFO_AND_SETTINGS_ADMIN) != 0) {
|
||||
flags |= telegram_api::chatAdminRights::CHANGE_INFO_MASK;
|
||||
}
|
||||
if (can_post_messages()) {
|
||||
flags |= telegram_api::chatAdminRights::POST_MESSAGES_MASK;
|
||||
}
|
||||
if (can_edit_messages()) {
|
||||
flags |= telegram_api::chatAdminRights::EDIT_MESSAGES_MASK;
|
||||
}
|
||||
if (can_delete_messages()) {
|
||||
flags |= telegram_api::chatAdminRights::DELETE_MESSAGES_MASK;
|
||||
}
|
||||
if ((flags_ & CAN_INVITE_USERS_ADMIN) != 0) {
|
||||
flags |= telegram_api::chatAdminRights::INVITE_USERS_MASK;
|
||||
}
|
||||
if (can_restrict_members()) {
|
||||
flags |= telegram_api::chatAdminRights::BAN_USERS_MASK;
|
||||
}
|
||||
if ((flags_ & CAN_PIN_MESSAGES_ADMIN) != 0) {
|
||||
flags |= telegram_api::chatAdminRights::PIN_MESSAGES_MASK;
|
||||
}
|
||||
if (can_promote_members()) {
|
||||
flags |= telegram_api::chatAdminRights::ADD_ADMINS_MASK;
|
||||
}
|
||||
if (can_manage_calls()) {
|
||||
flags |= telegram_api::chatAdminRights::MANAGE_CALL_MASK;
|
||||
}
|
||||
if (is_anonymous()) {
|
||||
flags |= telegram_api::chatAdminRights::ANONYMOUS_MASK;
|
||||
}
|
||||
if (can_manage_dialog()) {
|
||||
flags |= telegram_api::chatAdminRights::OTHER_MASK;
|
||||
}
|
||||
|
||||
LOG(INFO) << "Create chat admin rights " << flags;
|
||||
return make_tl_object<telegram_api::chatAdminRights>(
|
||||
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
|
||||
false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/);
|
||||
return get_administrator_rights().get_chat_admin_rights(is_anonymous());
|
||||
}
|
||||
|
||||
tl_object_ptr<telegram_api::chatBannedRights> DialogParticipantStatus::get_chat_banned_rights() const {
|
||||
|
@ -22,23 +22,27 @@ namespace td {
|
||||
class Td;
|
||||
|
||||
class AdministratorRights {
|
||||
static constexpr uint32 CAN_CHANGE_INFO_AND_SETTINGS_ADMIN = 1 << 0;
|
||||
static constexpr uint32 CAN_CHANGE_INFO_AND_SETTINGS = 1 << 0;
|
||||
static constexpr uint32 CAN_POST_MESSAGES = 1 << 1;
|
||||
static constexpr uint32 CAN_EDIT_MESSAGES = 1 << 2;
|
||||
static constexpr uint32 CAN_DELETE_MESSAGES = 1 << 3;
|
||||
static constexpr uint32 CAN_INVITE_USERS_ADMIN = 1 << 4;
|
||||
static constexpr uint32 CAN_INVITE_USERS = 1 << 4;
|
||||
// static constexpr uint32 CAN_EXPORT_DIALOG_INVITE_LINK = 1 << 5;
|
||||
static constexpr uint32 CAN_RESTRICT_MEMBERS = 1 << 6;
|
||||
static constexpr uint32 CAN_PIN_MESSAGES_ADMIN = 1 << 7;
|
||||
static constexpr uint32 CAN_PIN_MESSAGES = 1 << 7;
|
||||
static constexpr uint32 CAN_PROMOTE_MEMBERS = 1 << 8;
|
||||
static constexpr uint32 CAN_MANAGE_CALLS = 1 << 9;
|
||||
static constexpr uint32 CAN_MANAGE_DIALOG = 1 << 10;
|
||||
|
||||
static constexpr uint32 ALL_ADMINISTRATOR_RIGHTS =
|
||||
CAN_CHANGE_INFO_AND_SETTINGS | CAN_POST_MESSAGES | CAN_EDIT_MESSAGES | CAN_DELETE_MESSAGES | CAN_INVITE_USERS |
|
||||
CAN_RESTRICT_MEMBERS | CAN_PIN_MESSAGES | CAN_PROMOTE_MEMBERS | CAN_MANAGE_CALLS | CAN_MANAGE_DIALOG;
|
||||
|
||||
uint32 flags_;
|
||||
|
||||
friend class DialogParticipantStatus;
|
||||
|
||||
explicit AdministratorRights(int32 flags) : flags_(flags) {
|
||||
explicit AdministratorRights(int32 flags) : flags_(flags & ALL_ADMINISTRATOR_RIGHTS) {
|
||||
}
|
||||
|
||||
public:
|
||||
@ -46,12 +50,14 @@ class AdministratorRights {
|
||||
bool can_delete_messages, bool can_invite_users, bool can_restrict_members, bool can_pin_messages,
|
||||
bool can_promote_members, bool can_manage_calls);
|
||||
|
||||
telegram_api::object_ptr<telegram_api::chatAdminRights> get_chat_admin_rights(bool is_anonymous) const;
|
||||
|
||||
bool can_manage_dialog() const {
|
||||
return (flags_ & CAN_MANAGE_DIALOG) != 0;
|
||||
}
|
||||
|
||||
bool can_change_info_and_settings() const {
|
||||
return (flags_ & CAN_CHANGE_INFO_AND_SETTINGS_ADMIN) != 0;
|
||||
return (flags_ & CAN_CHANGE_INFO_AND_SETTINGS) != 0;
|
||||
}
|
||||
|
||||
bool can_post_messages() const {
|
||||
@ -67,12 +73,12 @@ class AdministratorRights {
|
||||
}
|
||||
|
||||
bool can_invite_users() const {
|
||||
return (flags_ & CAN_INVITE_USERS_ADMIN) != 0;
|
||||
return (flags_ & CAN_INVITE_USERS) != 0;
|
||||
}
|
||||
|
||||
bool can_manage_invite_links() const {
|
||||
// invite links can be managed, only if administrator was explicitly granted the right
|
||||
return (flags_ & CAN_INVITE_USERS_ADMIN) != 0;
|
||||
return (flags_ & CAN_INVITE_USERS) != 0;
|
||||
}
|
||||
|
||||
bool can_restrict_members() const {
|
||||
@ -80,7 +86,7 @@ class AdministratorRights {
|
||||
}
|
||||
|
||||
bool can_pin_messages() const {
|
||||
return (flags_ & CAN_PIN_MESSAGES_ADMIN) != 0;
|
||||
return (flags_ & CAN_PIN_MESSAGES) != 0;
|
||||
}
|
||||
|
||||
bool can_promote_members() const {
|
||||
@ -204,18 +210,6 @@ bool operator!=(const RestrictedRights &lhs, const RestrictedRights &rhs);
|
||||
StringBuilder &operator<<(StringBuilder &string_builder, const RestrictedRights &status);
|
||||
|
||||
class DialogParticipantStatus {
|
||||
static constexpr uint32 CAN_CHANGE_INFO_AND_SETTINGS_ADMIN = 1 << 0;
|
||||
static constexpr uint32 CAN_POST_MESSAGES = 1 << 1;
|
||||
static constexpr uint32 CAN_EDIT_MESSAGES = 1 << 2;
|
||||
static constexpr uint32 CAN_DELETE_MESSAGES = 1 << 3;
|
||||
static constexpr uint32 CAN_INVITE_USERS_ADMIN = 1 << 4;
|
||||
// static constexpr uint32 CAN_EXPORT_DIALOG_INVITE_LINK = 1 << 5;
|
||||
static constexpr uint32 CAN_RESTRICT_MEMBERS = 1 << 6;
|
||||
static constexpr uint32 CAN_PIN_MESSAGES_ADMIN = 1 << 7;
|
||||
static constexpr uint32 CAN_PROMOTE_MEMBERS = 1 << 8;
|
||||
static constexpr uint32 CAN_MANAGE_CALLS = 1 << 9;
|
||||
static constexpr uint32 CAN_MANAGE_DIALOG = 1 << 10;
|
||||
|
||||
static constexpr uint32 CAN_BE_EDITED = 1 << 15;
|
||||
|
||||
static constexpr uint32 CAN_SEND_MESSAGES = 1 << 16;
|
||||
@ -238,11 +232,6 @@ class DialogParticipantStatus {
|
||||
static constexpr int TYPE_SHIFT = 28;
|
||||
static constexpr uint32 HAS_UNTIL_DATE = 1u << 31;
|
||||
|
||||
static constexpr uint32 ALL_ADMINISTRATOR_RIGHTS = CAN_CHANGE_INFO_AND_SETTINGS_ADMIN | CAN_POST_MESSAGES |
|
||||
CAN_EDIT_MESSAGES | CAN_DELETE_MESSAGES | CAN_INVITE_USERS_ADMIN |
|
||||
CAN_RESTRICT_MEMBERS | CAN_PIN_MESSAGES_ADMIN |
|
||||
CAN_PROMOTE_MEMBERS | CAN_MANAGE_CALLS | CAN_MANAGE_DIALOG;
|
||||
|
||||
static constexpr uint32 ALL_ADMIN_PERMISSION_RIGHTS =
|
||||
CAN_CHANGE_INFO_AND_SETTINGS_BANNED | CAN_INVITE_USERS_BANNED | CAN_PIN_MESSAGES_BANNED;
|
||||
|
||||
@ -292,7 +281,7 @@ class DialogParticipantStatus {
|
||||
static DialogParticipantStatus ChannelAdministrator(bool is_creator, bool is_megagroup);
|
||||
|
||||
AdministratorRights get_administrator_rights() const {
|
||||
return AdministratorRights(flags_ & ALL_ADMINISTRATOR_RIGHTS);
|
||||
return AdministratorRights(flags_);
|
||||
}
|
||||
|
||||
RestrictedRights get_restricted_rights() const;
|
||||
@ -468,9 +457,9 @@ class DialogParticipantStatus {
|
||||
flags_ = stored_flags & ((1 << TYPE_SHIFT) - 1);
|
||||
|
||||
if (is_creator()) {
|
||||
flags_ |= ALL_ADMINISTRATOR_RIGHTS | ALL_PERMISSION_RIGHTS;
|
||||
flags_ |= AdministratorRights::ALL_ADMINISTRATOR_RIGHTS | ALL_PERMISSION_RIGHTS;
|
||||
} else if (is_administrator()) {
|
||||
flags_ |= CAN_MANAGE_DIALOG;
|
||||
flags_ |= AdministratorRights::CAN_MANAGE_DIALOG;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user