Add td_api::chatAdministratorRights.

This commit is contained in:
levlam 2022-03-22 13:17:48 +03:00
parent fa4e17fe95
commit ef8d959e98
4 changed files with 67 additions and 34 deletions

View File

@ -480,6 +480,20 @@ chatAdministrators administrators:vector<chatAdministrator> = ChatAdministrators
//@can_pin_messages True, if the user can pin messages //@can_pin_messages True, if the user can pin messages
chatPermissions can_send_messages:Bool can_send_media_messages:Bool can_send_polls:Bool can_send_other_messages:Bool can_add_web_page_previews:Bool can_change_info:Bool can_invite_users:Bool can_pin_messages:Bool = ChatPermissions; chatPermissions can_send_messages:Bool can_send_media_messages:Bool can_send_polls:Bool can_send_other_messages:Bool can_add_web_page_previews:Bool can_change_info:Bool can_invite_users:Bool can_pin_messages:Bool = ChatPermissions;
//@description Describes rights of the administrator
//@can_manage_chat True, if the administrator can get chat event log, get chat statistics, get message statistics in channels, get channel members, see anonymous administrators in supergroups and ignore slow mode. Implied by any other privilege; applicable to supergroups and channels only
//@can_change_info True, if the administrator can change the chat title, photo, and other settings
//@can_post_messages True, if the administrator can create channel posts; applicable to channels only
//@can_edit_messages True, if the administrator can edit messages of other users and pin messages; applicable to channels only
//@can_delete_messages True, if the administrator can delete messages of other users
//@can_invite_users True, if the administrator can invite new users to the chat
//@can_restrict_members True, if the administrator can restrict, ban, or unban chat members; always true for channels
//@can_pin_messages True, if the administrator can pin messages; applicable to basic groups and supergroups only
//@can_promote_members True, if the administrator can add new administrators with a subset of their own privileges or demote administrators that were directly or indirectly promoted by them
//@can_manage_video_chats True, if the administrator can manage video chats
//@is_anonymous True, if the administrator isn't shown in the chat member list and sends messages anonymously; applicable to supergroups only
chatAdministratorRights can_manage_chat:Bool can_change_info:Bool can_post_messages:Bool can_edit_messages:Bool can_delete_messages:Bool can_invite_users:Bool can_restrict_members:Bool can_pin_messages:Bool can_promote_members:Bool can_manage_video_chats:Bool is_anonymous:Bool = ChatAdministratorRights;
//@class ChatMemberStatus @description Provides information about the status of a member in a chat //@class ChatMemberStatus @description Provides information about the status of a member in a chat
@ -492,18 +506,8 @@ chatMemberStatusCreator custom_title:string is_anonymous:Bool is_member:Bool = C
//@description The user is a member of the chat and has some additional privileges. In basic groups, administrators can edit and delete messages sent by others, add new members, ban unprivileged members, and manage video chats. In supergroups and channels, there are more detailed options for administrator privileges //@description The user is a member of the chat and has some additional privileges. In basic groups, administrators can edit and delete messages sent by others, add new members, ban unprivileged members, and manage video chats. In supergroups and channels, there are more detailed options for administrator privileges
//@custom_title A custom title of the administrator; 0-16 characters without emojis; applicable to supergroups only //@custom_title A custom title of the administrator; 0-16 characters without emojis; applicable to supergroups only
//@can_be_edited True, if the current user can edit the administrator privileges for the called user //@can_be_edited True, if the current user can edit the administrator privileges for the called user
//@can_manage_chat True, if the administrator can get chat event log, get chat statistics, get message statistics in channels, get channel members, see anonymous administrators in supergroups and ignore slow mode. Implied by any other privilege; applicable to supergroups and channels only //@rights Rights of the administrator
//@can_change_info True, if the administrator can change the chat title, photo, and other settings chatMemberStatusAdministrator custom_title:string can_be_edited:Bool rights:chatAdministratorRights = ChatMemberStatus;
//@can_post_messages True, if the administrator can create channel posts; applicable to channels only
//@can_edit_messages True, if the administrator can edit messages of other users and pin messages; applicable to channels only
//@can_delete_messages True, if the administrator can delete messages of other users
//@can_invite_users True, if the administrator can invite new users to the chat
//@can_restrict_members True, if the administrator can restrict, ban, or unban chat members; always true for channels
//@can_pin_messages True, if the administrator can pin messages; applicable to basic groups and supergroups only
//@can_promote_members True, if the administrator can add new administrators with a subset of their own privileges or demote administrators that were directly or indirectly promoted by them
//@can_manage_video_chats True, if the administrator can manage video chats
//@is_anonymous True, if the administrator isn't shown in the chat member list and sends messages anonymously; applicable to supergroups only
chatMemberStatusAdministrator custom_title:string can_be_edited:Bool can_manage_chat:Bool can_change_info:Bool can_post_messages:Bool can_edit_messages:Bool can_delete_messages:Bool can_invite_users:Bool can_restrict_members:Bool can_pin_messages:Bool can_promote_members:Bool can_manage_video_chats:Bool is_anonymous:Bool = ChatMemberStatus;
//@description The user is a member of the chat, without any additional privileges or restrictions //@description The user is a member of the chat, without any additional privileges or restrictions
chatMemberStatusMember = ChatMemberStatus; chatMemberStatusMember = ChatMemberStatus;

View File

@ -79,6 +79,13 @@ telegram_api::object_ptr<telegram_api::chatAdminRights> AdministratorRights::get
false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/); false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/);
} }
td_api::object_ptr<td_api::chatAdministratorRights> AdministratorRights::get_chat_administrator_rights_object() const {
return td_api::make_object<td_api::chatAdministratorRights>(
can_manage_dialog(), 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(), is_anonymous());
}
bool operator==(const AdministratorRights &lhs, const AdministratorRights &rhs) { bool operator==(const AdministratorRights &lhs, const AdministratorRights &rhs) {
return lhs.flags_ == rhs.flags_; return lhs.flags_ == rhs.flags_;
} }
@ -356,9 +363,7 @@ tl_object_ptr<td_api::ChatMemberStatus> DialogParticipantStatus::get_chat_member
return td_api::make_object<td_api::chatMemberStatusCreator>(rank_, is_anonymous(), is_member()); return td_api::make_object<td_api::chatMemberStatusCreator>(rank_, is_anonymous(), is_member());
case Type::Administrator: case Type::Administrator:
return td_api::make_object<td_api::chatMemberStatusAdministrator>( return td_api::make_object<td_api::chatMemberStatusAdministrator>(
rank_, can_be_edited(), can_manage_dialog(), can_change_info_and_settings(), can_post_messages(), rank_, can_be_edited(), get_administrator_rights().get_chat_administrator_rights_object());
can_edit_messages(), can_delete_messages(), can_invite_users(), can_restrict_members(), can_pin_messages(),
can_promote_members(), can_manage_calls(), is_anonymous());
case Type::Member: case Type::Member:
return td_api::make_object<td_api::chatMemberStatusMember>(); return td_api::make_object<td_api::chatMemberStatusMember>();
case Type::Restricted: case Type::Restricted:
@ -515,12 +520,8 @@ DialogParticipantStatus get_dialog_participant_status(const tl_object_ptr<td_api
if (!clean_input_string(custom_title)) { if (!clean_input_string(custom_title)) {
custom_title.clear(); custom_title.clear();
} }
AdministratorRights administrator_rights(st->is_anonymous_, st->can_manage_chat_, st->can_change_info_, return DialogParticipantStatus::Administrator(::td::get_administrator_rights(st->rights_),
st->can_post_messages_, st->can_edit_messages_, st->can_delete_messages_, std::move(custom_title), true /*st->can_be_edited_*/);
st->can_invite_users_, st->can_restrict_members_, st->can_pin_messages_,
st->can_promote_members_, st->can_manage_video_chats_);
return DialogParticipantStatus::Administrator(administrator_rights, std::move(custom_title),
true /*st->can_be_edited_*/);
} }
case td_api::chatMemberStatusMember::ID: case td_api::chatMemberStatusMember::ID:
return DialogParticipantStatus::Member(); return DialogParticipantStatus::Member();
@ -555,6 +556,16 @@ AdministratorRights get_administrator_rights(tl_object_ptr<telegram_api::chatAdm
admin_rights->add_admins_, admin_rights->manage_call_); admin_rights->add_admins_, admin_rights->manage_call_);
} }
AdministratorRights get_administrator_rights(const td_api::object_ptr<td_api::chatAdministratorRights> &rights) {
if (rights == nullptr) {
return AdministratorRights(false, false, false, false, false, false, false, false, false, false, false);
}
return AdministratorRights(rights->is_anonymous_, rights->can_manage_chat_, rights->can_change_info_,
rights->can_post_messages_, rights->can_edit_messages_, rights->can_delete_messages_,
rights->can_invite_users_, rights->can_restrict_members_, rights->can_pin_messages_,
rights->can_promote_members_, rights->can_manage_video_chats_);
}
RestrictedRights get_restricted_rights(tl_object_ptr<telegram_api::chatBannedRights> &&banned_rights) { RestrictedRights get_restricted_rights(tl_object_ptr<telegram_api::chatBannedRights> &&banned_rights) {
if (banned_rights == nullptr) { if (banned_rights == nullptr) {
return RestrictedRights(false, false, false, false, false, false, false, false, false, false, false); return RestrictedRights(false, false, false, false, false, false, false, false, false, false, false);

View File

@ -54,6 +54,8 @@ class AdministratorRights {
telegram_api::object_ptr<telegram_api::chatAdminRights> get_chat_admin_rights() const; telegram_api::object_ptr<telegram_api::chatAdminRights> get_chat_admin_rights() const;
td_api::object_ptr<td_api::chatAdministratorRights> get_chat_administrator_rights_object() const;
bool can_manage_dialog() const { bool can_manage_dialog() const {
return (flags_ & CAN_MANAGE_DIALOG) != 0; return (flags_ & CAN_MANAGE_DIALOG) != 0;
} }
@ -543,6 +545,8 @@ DialogParticipantStatus get_dialog_participant_status(const tl_object_ptr<td_api
AdministratorRights get_administrator_rights(tl_object_ptr<telegram_api::chatAdminRights> &&admin_rights); AdministratorRights get_administrator_rights(tl_object_ptr<telegram_api::chatAdminRights> &&admin_rights);
AdministratorRights get_administrator_rights(const td_api::object_ptr<td_api::chatAdministratorRights> &rights);
RestrictedRights get_restricted_rights(tl_object_ptr<telegram_api::chatBannedRights> &&banned_rights); RestrictedRights get_restricted_rights(tl_object_ptr<telegram_api::chatBannedRights> &&banned_rights);
RestrictedRights get_restricted_rights(const td_api::object_ptr<td_api::chatPermissions> &permissions); RestrictedRights get_restricted_rights(const td_api::object_ptr<td_api::chatPermissions> &permissions);

View File

@ -1346,6 +1346,15 @@ class CliClient final : public Actor {
rand_bool(), rand_bool(), rand_bool(), rand_bool(), rand_bool(), rand_bool(), rand_bool(), rand_bool()); rand_bool(), rand_bool(), rand_bool(), rand_bool(), rand_bool(), rand_bool(), rand_bool(), rand_bool());
} }
static td_api::object_ptr<td_api::chatAdministratorRights> as_chat_administrator_rights(
bool can_manage_chat, bool can_change_info, bool can_post_messages, bool can_edit_messages,
bool can_delete_messages, bool can_invite_users, bool can_restrict_members, bool can_pin_messages,
bool can_promote_members, bool can_manage_video_chats, bool is_anonymous) {
return td_api::make_object<td_api::chatAdministratorRights>(
can_manage_chat, 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_video_chats, is_anonymous);
}
static td_api::object_ptr<td_api::TopChatCategory> get_top_chat_category(MutableSlice category) { static td_api::object_ptr<td_api::TopChatCategory> get_top_chat_category(MutableSlice category) {
category = trim(category); category = trim(category);
to_lower_inplace(category); to_lower_inplace(category);
@ -4168,29 +4177,34 @@ class CliClient final : public Actor {
} else if (status_str == "uncreator") { } else if (status_str == "uncreator") {
status = td_api::make_object<td_api::chatMemberStatusCreator>("", false, false); status = td_api::make_object<td_api::chatMemberStatusCreator>("", false, false);
} else if (status_str == "anonadmin") { } else if (status_str == "anonadmin") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>("anon", true, true, true, true, true, true, status = td_api::make_object<td_api::chatMemberStatusAdministrator>(
true, true, true, true, true, true); "anon", true,
as_chat_administrator_rights(true, true, true, true, true, true, true, true, true, true, true));
} else if (status_str == "anon") { } else if (status_str == "anon") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>( status = td_api::make_object<td_api::chatMemberStatusAdministrator>(
"anon", false, false, false, false, false, false, false, false, false, false, false, true); "anon", false,
as_chat_administrator_rights(false, false, false, false, false, false, false, false, false, false, true));
} else if (status_str == "addadmin") { } else if (status_str == "addadmin") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>( status = td_api::make_object<td_api::chatMemberStatusAdministrator>(
"anon", false, false, false, false, false, false, false, false, false, true, false, false); "anon", false,
as_chat_administrator_rights(false, false, false, false, false, false, false, false, true, false, false));
} else if (status_str == "calladmin") { } else if (status_str == "calladmin") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>( status = td_api::make_object<td_api::chatMemberStatusAdministrator>(
"anon", false, false, false, false, false, false, false, false, false, false, true, false); "anon", false,
as_chat_administrator_rights(false, false, false, false, false, false, false, false, false, true, false));
} else if (status_str == "admin") { } else if (status_str == "admin") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>("", true, false, true, true, true, true, status = td_api::make_object<td_api::chatMemberStatusAdministrator>(
true, true, true, true, true, false); "", true, as_chat_administrator_rights(false, true, true, true, true, true, true, true, true, true, false));
} else if (status_str == "adminq") { } else if (status_str == "adminq") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>("title", true, false, true, true, true, status = td_api::make_object<td_api::chatMemberStatusAdministrator>(
true, true, true, true, true, true, false); "title", true,
as_chat_administrator_rights(false, true, true, true, true, true, true, true, true, true, false));
} else if (status_str == "minadmin") { } else if (status_str == "minadmin") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>("", true, true, false, false, false, false, status = td_api::make_object<td_api::chatMemberStatusAdministrator>(
false, false, false, false, false, false); "", true,
as_chat_administrator_rights(true, false, false, false, false, false, false, false, false, false, false));
} else if (status_str == "unadmin") { } else if (status_str == "unadmin") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>("", true, false, false, false, false, false, status = td_api::make_object<td_api::chatMemberStatusAdministrator>("", true, nullptr);
false, false, false, false, false, false);
} else if (status_str == "rest") { } else if (status_str == "rest") {
status = td_api::make_object<td_api::chatMemberStatusRestricted>( status = td_api::make_object<td_api::chatMemberStatusRestricted>(
true, static_cast<int32>(120 + std::time(nullptr)), true, static_cast<int32>(120 + std::time(nullptr)),