Add support for is_anonymous administrator right.

GitOrigin-RevId: d0d46d961aebcc67275bb09ec883f6feaa465c63
This commit is contained in:
levlam 2020-09-11 01:49:15 +03:00
parent 2c0a9367ac
commit 01f3eecd85
7 changed files with 74 additions and 46 deletions

View File

@ -441,11 +441,13 @@ chatPermissions can_send_messages:Bool can_send_media_messages:Bool can_send_pol
//@class ChatMemberStatus @description Provides information about the status of a member in a chat
//@description The user is the owner of a chat and has all the administrator privileges
//@is_anonymous True, if the creator isn't shown in the chat member list and sends messages anonymously
//@custom_title A custom title of the owner; 0-16 characters without emojis; applicable to supergroups only
//@is_member True, if the user is a member of the chat
chatMemberStatusCreator custom_title:string is_member:Bool = ChatMemberStatus;
chatMemberStatusCreator is_anonymous:Bool custom_title:string is_member:Bool = ChatMemberStatus;
//@description The user is a member of a chat and has some additional privileges. In basic groups, administrators can edit and delete messages sent by others, add new members, and ban unprivileged members. In supergroups and channels, there are more detailed options for administrator privileges
//@is_anonymous True, if the administrator isn't shown in the chat member list and sends messages anonymously
//@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_change_info True, if the administrator can change the chat title, photo, and other settings
@ -456,7 +458,7 @@ chatMemberStatusCreator custom_title:string is_member:Bool = ChatMemberStatus;
//@can_restrict_members True, if the administrator can restrict, ban, or unban chat members
//@can_pin_messages True, if the administrator can pin messages; applicable to groups 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
chatMemberStatusAdministrator custom_title:string can_be_edited: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 = ChatMemberStatus;
chatMemberStatusAdministrator is_anonymous:Bool custom_title:string can_be_edited: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 = ChatMemberStatus;
//@description The user is a member of a chat, without any additional privileges or restrictions
chatMemberStatusMember = ChatMemberStatus;

Binary file not shown.

View File

@ -3545,7 +3545,7 @@ void ContactsManager::Chat::parse(ParserT &parser) {
} else if (left) {
status = DialogParticipantStatus::Left();
} else if (is_creator) {
status = DialogParticipantStatus::Creator(true, string());
status = DialogParticipantStatus::Creator(true, false, string());
} else if (is_administrator && !everyone_is_administrator) {
status = DialogParticipantStatus::GroupAdministrator(false);
} else {
@ -3724,7 +3724,7 @@ void ContactsManager::Channel::parse(ParserT &parser) {
} else if (left) {
status = DialogParticipantStatus::Left();
} else if (is_creator) {
status = DialogParticipantStatus::Creator(true, string());
status = DialogParticipantStatus::Creator(true, false, string());
} else if (can_edit || can_moderate) {
status = DialogParticipantStatus::ChannelAdministrator(false, is_megagroup);
} else {
@ -6400,9 +6400,9 @@ void ContactsManager::change_channel_participant_status_impl(ChannelId channel_i
return promise.set_error(Status::Error(3, "Can't remove chat owner"));
}
if (status.is_member() == old_status.is_member()) {
// change rank
// change rank and is_anonymous
if (user_id != get_my_id()) {
return promise.set_error(Status::Error(3, "Not enough rights to change chat owner custom title"));
return promise.set_error(Status::Error(3, "Not enough rights to change chat owner rights"));
}
auto input_user = get_input_user(user_id);
@ -10503,7 +10503,7 @@ void ContactsManager::on_get_chat_participants(tl_object_ptr<telegram_api::ChatP
auto participant = move_tl_object_as<telegram_api::chatParticipantCreator>(participant_ptr);
new_creator_user_id = UserId(participant->user_id_);
dialog_participant = {new_creator_user_id, new_creator_user_id, c->date,
DialogParticipantStatus::Creator(true, string())};
DialogParticipantStatus::Creator(true, false, string())};
break;
}
case telegram_api::chatParticipantAdmin::ID: {
@ -11567,7 +11567,7 @@ void ContactsManager::on_update_chat_add_user(ChatId chat_id, UserId inviter_use
}
chat_full->participants.push_back(DialogParticipant{user_id, inviter_user_id, date,
user_id == chat_full->creator_user_id
? DialogParticipantStatus::Creator(true, string())
? DialogParticipantStatus::Creator(true, false, string())
: DialogParticipantStatus::Member()});
update_chat_online_member_count(chat_full, chat_id, false);
chat_full->is_changed = true;
@ -13703,7 +13703,7 @@ void ContactsManager::on_chat_update(telegram_api::chat &chat, const char *sourc
}
if (is_creator) {
return DialogParticipantStatus::Creator(!has_left, string());
return DialogParticipantStatus::Creator(!has_left, false, string());
} else if (chat.admin_rights_ != nullptr) {
return get_dialog_participant_status(false, std::move(chat.admin_rights_), string());
} else if (was_kicked) {
@ -13864,7 +13864,7 @@ void ContactsManager::on_chat_update(telegram_api::channel &channel, const char
bool is_creator = (channel.flags_ & CHANNEL_FLAG_USER_IS_CREATOR) != 0;
if (is_creator) {
return DialogParticipantStatus::Creator(!has_left, string());
return DialogParticipantStatus::Creator(!has_left, false, string());
} else if (channel.admin_rights_ != nullptr) {
return get_dialog_participant_status(false, std::move(channel.admin_rights_), string());
} else if (channel.banned_rights_ != nullptr) {

View File

@ -27,17 +27,18 @@ int32 DialogParticipantStatus::fix_until_date(int32 date) {
return date;
}
DialogParticipantStatus DialogParticipantStatus::Creator(bool is_member, string rank) {
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), 0,
std::move(rank));
ALL_ADMINISTRATOR_RIGHTS | ALL_PERMISSION_RIGHTS | (is_member ? IS_MEMBER : 0) |
(is_anonymous ? IS_ANONYMOUS : 0),
0, std::move(rank));
}
DialogParticipantStatus DialogParticipantStatus::Administrator(string rank, bool can_be_edited, 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) {
DialogParticipantStatus DialogParticipantStatus::Administrator(bool is_anonymous, string rank, bool can_be_edited,
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) {
uint32 flags = (static_cast<uint32>(can_be_edited) * CAN_BE_EDITED) |
(static_cast<uint32>(can_change_info) * CAN_CHANGE_INFO_AND_SETTINGS_ADMIN) |
(static_cast<uint32>(can_post_messages) * CAN_POST_MESSAGES) |
@ -50,7 +51,9 @@ DialogParticipantStatus DialogParticipantStatus::Administrator(string rank, bool
if (flags == 0 || flags == CAN_BE_EDITED) {
return Member();
}
return DialogParticipantStatus(Type::Administrator, IS_MEMBER | ALL_RESTRICTED_RIGHTS | flags, 0, std::move(rank));
return DialogParticipantStatus(Type::Administrator,
IS_MEMBER | ALL_RESTRICTED_RIGHTS | flags | (is_anonymous ? IS_ANONYMOUS : 0), 0,
std::move(rank));
}
DialogParticipantStatus DialogParticipantStatus::Member() {
@ -88,14 +91,14 @@ DialogParticipantStatus DialogParticipantStatus::Banned(int32 banned_until_date)
}
DialogParticipantStatus DialogParticipantStatus::GroupAdministrator(bool is_creator) {
return Administrator(string(), is_creator, true, false, false, true, true, true, true, false);
return Administrator(false, string(), is_creator, true, false, false, true, true, true, true, false);
}
DialogParticipantStatus DialogParticipantStatus::ChannelAdministrator(bool is_creator, bool is_megagroup) {
if (is_megagroup) {
return Administrator(string(), is_creator, true, false, false, true, true, true, true, false);
return Administrator(false, string(), is_creator, true, false, false, true, true, true, true, false);
} else {
return Administrator(string(), is_creator, false, true, true, true, false, true, false, false);
return Administrator(false, string(), is_creator, false, true, true, true, false, true, false, false);
}
}
@ -108,11 +111,12 @@ RestrictedRights DialogParticipantStatus::get_restricted_rights() const {
tl_object_ptr<td_api::ChatMemberStatus> DialogParticipantStatus::get_chat_member_status_object() const {
switch (type_) {
case Type::Creator:
return td_api::make_object<td_api::chatMemberStatusCreator>(rank_, is_member());
return td_api::make_object<td_api::chatMemberStatusCreator>(is_anonymous(), rank_, is_member());
case Type::Administrator:
return td_api::make_object<td_api::chatMemberStatusAdministrator>(
rank_, can_be_edited(), 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());
is_anonymous(), rank_, can_be_edited(), 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());
case Type::Member:
return td_api::make_object<td_api::chatMemberStatusMember>();
case Type::Restricted:
@ -154,6 +158,9 @@ tl_object_ptr<telegram_api::chatAdminRights> DialogParticipantStatus::get_chat_a
if (can_promote_members()) {
flags |= telegram_api::chatAdminRights::ADD_ADMINS_MASK;
}
if (is_anonymous()) {
flags |= telegram_api::chatAdminRights::ANONYMOUS_MASK;
}
LOG(INFO) << "Create chat admin rights " << flags;
return make_tl_object<telegram_api::chatAdminRights>(flags, false /*ignored*/, false /*ignored*/, false /*ignored*/,
@ -278,6 +285,9 @@ StringBuilder &operator<<(StringBuilder &string_builder, const DialogParticipant
if (!status.rank_.empty()) {
string_builder << " [" << status.rank_ << "]";
}
if (status.is_anonymous()) {
string_builder << "-anonymous";
}
return string_builder;
case DialogParticipantStatus::Type::Administrator:
string_builder << "Administrator: ";
@ -308,6 +318,9 @@ StringBuilder &operator<<(StringBuilder &string_builder, const DialogParticipant
if (!status.rank_.empty()) {
string_builder << " [" << status.rank_ << "]";
}
if (status.is_anonymous()) {
string_builder << "-anonymous";
}
return string_builder;
case DialogParticipantStatus::Type::Member:
return string_builder << "Member";
@ -377,14 +390,14 @@ DialogParticipantStatus get_dialog_participant_status(const tl_object_ptr<td_api
switch (constructor_id) {
case td_api::chatMemberStatusCreator::ID: {
auto st = static_cast<const td_api::chatMemberStatusCreator *>(status.get());
return DialogParticipantStatus::Creator(st->is_member_, st->custom_title_);
return DialogParticipantStatus::Creator(st->is_member_, st->is_anonymous_, st->custom_title_);
}
case td_api::chatMemberStatusAdministrator::ID: {
auto st = static_cast<const td_api::chatMemberStatusAdministrator *>(status.get());
return DialogParticipantStatus::Administrator(
st->custom_title_, st->can_be_edited_, st->can_change_info_, st->can_post_messages_, st->can_edit_messages_,
st->can_delete_messages_, st->can_invite_users_, st->can_restrict_members_, st->can_pin_messages_,
st->can_promote_members_);
st->is_anonymous_, st->custom_title_, st->can_be_edited_, st->can_change_info_, st->can_post_messages_,
st->can_edit_messages_, st->can_delete_messages_, st->can_invite_users_, st->can_restrict_members_,
st->can_pin_messages_, st->can_promote_members_);
}
case td_api::chatMemberStatusMember::ID:
return DialogParticipantStatus::Member();
@ -425,9 +438,10 @@ DialogParticipantStatus get_dialog_participant_status(bool can_be_edited,
bool can_restrict_members = (admin_rights->flags_ & telegram_api::chatAdminRights::BAN_USERS_MASK) != 0;
bool can_pin_messages = (admin_rights->flags_ & telegram_api::chatAdminRights::PIN_MESSAGES_MASK) != 0;
bool can_promote_members = (admin_rights->flags_ & telegram_api::chatAdminRights::ADD_ADMINS_MASK) != 0;
return DialogParticipantStatus::Administrator(std::move(rank), can_be_edited, can_change_info, can_post_messages,
can_edit_messages, can_delete_messages, can_invite_users,
can_restrict_members, can_pin_messages, can_promote_members);
bool is_anonymous = (admin_rights->flags_ & telegram_api::chatAdminRights::ANONYMOUS_MASK) != 0;
return DialogParticipantStatus::Administrator(
is_anonymous, std::move(rank), can_be_edited, can_change_info, can_post_messages, can_edit_messages,
can_delete_messages, can_invite_users, can_restrict_members, can_pin_messages, can_promote_members);
}
DialogParticipantStatus get_dialog_participant_status(
@ -635,8 +649,9 @@ DialogParticipant::DialogParticipant(tl_object_ptr<telegram_api::ChannelParticip
}
case telegram_api::channelParticipantCreator::ID: {
auto participant = move_tl_object_as<telegram_api::channelParticipantCreator>(participant_ptr);
bool is_anonymous = (participant->admin_rights_->flags_ & telegram_api::chatAdminRights::ANONYMOUS_MASK) != 0;
*this = {UserId(participant->user_id_), UserId(), 0,
DialogParticipantStatus::Creator(true, std::move(participant->rank_))};
DialogParticipantStatus::Creator(true, is_anonymous, std::move(participant->rank_))};
break;
}
case telegram_api::channelParticipantAdmin::ID: {

View File

@ -135,6 +135,7 @@ class DialogParticipantStatus {
static constexpr uint32 IS_MEMBER = 1 << 27;
static constexpr uint32 IS_ANONYMOUS = 1 << 13;
static constexpr uint32 HAS_RANK = 1u << 14;
// bits 28-30 reserved for Type
static constexpr int TYPE_SHIFT = 28;
@ -165,9 +166,9 @@ class DialogParticipantStatus {
DialogParticipantStatus(Type type, uint32 flags, int32 until_date, string rank);
public:
static DialogParticipantStatus Creator(bool is_member, string rank);
static DialogParticipantStatus Creator(bool is_member, bool is_anonymous, string rank);
static DialogParticipantStatus Administrator(string rank, bool can_be_edited, bool can_change_info,
static DialogParticipantStatus Administrator(bool is_anonymous, string rank, bool can_be_edited, 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);
@ -308,6 +309,10 @@ class DialogParticipantStatus {
return until_date_;
}
bool is_anonymous() const {
return (flags_ & IS_ANONYMOUS) != 0;
}
const string &get_rank() const {
return rank_;
}

View File

@ -6082,7 +6082,8 @@ void Td::on_request(uint64 id, const td_api::leaveChat &request) {
return promise.set_value(Unit());
}
new_status = td_api::make_object<td_api::chatMemberStatusCreator>(status.get_rank(), false);
new_status =
td_api::make_object<td_api::chatMemberStatusCreator>(status.is_anonymous(), status.get_rank(), false);
}
}
messages_manager_->set_dialog_participant_status(dialog_id, contacts_manager_->get_my_id(), std::move(new_status),

View File

@ -3717,21 +3717,26 @@ class CliClient final : public Actor {
} else if (status_str == "banned") {
status = td_api::make_object<td_api::chatMemberStatusBanned>(std::numeric_limits<int32>::max());
} else if (status_str == "creator") {
status = td_api::make_object<td_api::chatMemberStatusCreator>("", true);
status = td_api::make_object<td_api::chatMemberStatusCreator>(false, "", true);
} else if (status_str == "creatoranon") {
status = td_api::make_object<td_api::chatMemberStatusCreator>(true, "", true);
} else if (status_str == "uncreator") {
status = td_api::make_object<td_api::chatMemberStatusCreator>("", false);
status = td_api::make_object<td_api::chatMemberStatusCreator>(false, "", false);
} else if (status_str == "anon") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>(true, "anon", true, true, true, true, true,
true, true, true, true);
} else if (status_str == "admin") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>("", true, true, true, true, true, true,
true, true, true);
status = td_api::make_object<td_api::chatMemberStatusAdministrator>(false, "", true, true, true, true, true,
true, true, true, true);
} else if (status_str == "adminq") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>("title", true, true, true, true, true, true,
true, true, true);
status = td_api::make_object<td_api::chatMemberStatusAdministrator>(false, "title", true, true, true, true,
true, true, true, true, true);
} else if (status_str == "minadmin") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>("", true, true, false, false, false, false,
false, false, false);
status = td_api::make_object<td_api::chatMemberStatusAdministrator>(false, "", true, true, false, false, false,
false, false, false, false);
} else if (status_str == "unadmin") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>("", true, false, false, false, false, false,
false, false, false);
status = td_api::make_object<td_api::chatMemberStatusAdministrator>(false, "", true, false, false, false, false,
false, false, false, false);
} else if (status_str == "rest") {
status = td_api::make_object<td_api::chatMemberStatusRestricted>(
true, static_cast<int32>(120 + std::time(nullptr)),