Support can_manage_topics administrator right and chat permission.

This commit is contained in:
levlam 2022-10-23 13:20:53 +03:00
parent 62bcac0198
commit 6a16492266
9 changed files with 144 additions and 82 deletions

View File

@ -452,7 +452,8 @@ inputChatPhotoAnimation animation:InputFile main_frame_timestamp:double = InputC
//@can_change_info True, if the user can change the chat title, photo, and other settings
//@can_invite_users True, if the user can invite new users to the chat
//@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;
//@can_manage_topics True, if the user can manage topics
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 can_manage_topics: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
@ -463,10 +464,11 @@ chatPermissions can_send_messages:Bool can_send_media_messages:Bool can_send_pol
//@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_manage_topics True, if the administrator can manage topics; applicable to forum 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;
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_manage_topics:Bool can_promote_members:Bool can_manage_video_chats:Bool is_anonymous:Bool = ChatAdministratorRights;
//@description Describes an option for buying Telegram Premium to a user

View File

@ -4322,7 +4322,7 @@ void ContactsManager::Chat::parse(ParserT &parser) {
status = DialogParticipantStatus::Member();
}
default_permissions = RestrictedRights(true, true, true, true, true, true, true, true, everyone_is_administrator,
everyone_is_administrator, everyone_is_administrator);
everyone_is_administrator, everyone_is_administrator, false);
}
if (has_default_permissions_version) {
parse(default_permissions_version, parser);
@ -4590,7 +4590,7 @@ void ContactsManager::Channel::parse(ParserT &parser) {
parse(default_permissions, parser);
} else {
default_permissions =
RestrictedRights(true, true, true, true, true, true, true, true, false, anyone_can_invite, false);
RestrictedRights(true, true, true, true, true, true, true, true, false, anyone_can_invite, false, false);
}
}
if (has_cache_version) {
@ -5196,15 +5196,15 @@ string ContactsManager::get_secret_chat_title(SecretChatId secret_chat_id) const
RestrictedRights ContactsManager::get_user_default_permissions(UserId user_id) const {
auto u = get_user(user_id);
if (u == nullptr || user_id == get_replies_bot_user_id()) {
return RestrictedRights(false, false, false, false, false, false, false, false, false, false, u != nullptr);
return RestrictedRights(false, false, false, false, false, false, false, false, false, false, u != nullptr, false);
}
return RestrictedRights(true, true, true, true, true, true, true, true, false, false, true);
return RestrictedRights(true, true, true, true, true, true, true, true, false, false, true, false);
}
RestrictedRights ContactsManager::get_chat_default_permissions(ChatId chat_id) const {
auto c = get_chat(chat_id);
if (c == 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, false);
}
return c->default_permissions;
}
@ -5212,7 +5212,7 @@ RestrictedRights ContactsManager::get_chat_default_permissions(ChatId chat_id) c
RestrictedRights ContactsManager::get_channel_default_permissions(ChannelId channel_id) const {
auto c = get_channel(channel_id);
if (c == 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, false);
}
return c->default_permissions;
}
@ -5220,9 +5220,9 @@ RestrictedRights ContactsManager::get_channel_default_permissions(ChannelId chan
RestrictedRights ContactsManager::get_secret_chat_default_permissions(SecretChatId secret_chat_id) const {
auto c = get_secret_chat(secret_chat_id);
if (c == 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, false);
}
return RestrictedRights(true, true, true, true, true, true, true, true, false, false, false);
return RestrictedRights(true, true, true, true, true, true, true, true, false, false, false, false);
}
bool ContactsManager::get_chat_has_protected_content(ChatId chat_id) const {
@ -10988,7 +10988,7 @@ void ContactsManager::update_channel(Channel *c, ChannelId channel_id, bool from
if (c->is_default_permissions_changed) {
td_->messages_manager_->on_dialog_default_permissions_updated(DialogId(channel_id));
if (c->default_permissions !=
RestrictedRights(false, false, false, false, false, false, false, false, false, false, false)) {
RestrictedRights(false, false, false, false, false, false, false, false, false, false, false, false)) {
remove_dialog_suggested_action(SuggestedAction{SuggestedAction::Type::ConvertToGigagroup, DialogId(channel_id)});
}
c->is_default_permissions_changed = false;
@ -11991,8 +11991,9 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
SuggestedAction suggested_action(action_str, DialogId(channel_id));
if (!suggested_action.is_empty()) {
if (suggested_action == SuggestedAction{SuggestedAction::Type::ConvertToGigagroup, DialogId(channel_id)} &&
(c->is_gigagroup || c->default_permissions != RestrictedRights(false, false, false, false, false, false,
false, false, false, false, false))) {
(c->is_gigagroup ||
c->default_permissions != RestrictedRights(false, false, false, false, false, false, false, false,
false, false, false, false))) {
LOG(INFO) << "Skip ConvertToGigagroup suggested action";
} else {
suggested_actions.push_back(suggested_action);

View File

@ -802,7 +802,8 @@ class ContactsManager final : public Actor {
ChannelId migrated_to_channel_id;
DialogParticipantStatus status = DialogParticipantStatus::Banned(0);
RestrictedRights default_permissions{false, false, false, false, false, false, false, false, false, false, false};
RestrictedRights default_permissions{false, false, false, false, false, false,
false, false, false, false, false, false};
static constexpr uint32 CACHE_VERSION = 4;
uint32 cache_version = 0;
@ -873,7 +874,8 @@ class ContactsManager final : public Actor {
Usernames usernames;
vector<RestrictionReason> restriction_reasons;
DialogParticipantStatus status = DialogParticipantStatus::Banned(0);
RestrictedRights default_permissions{false, false, false, false, false, false, false, false, false, false, false};
RestrictedRights default_permissions{false, false, false, false, false, false,
false, false, false, false, false, false};
int32 date = 0;
int32 participant_count = 0;

View File

@ -28,10 +28,10 @@ AdministratorRights::AdministratorRights(const tl_object_ptr<telegram_api::chatA
if (!rights->other_) {
LOG(ERROR) << "Receive wrong other flag in " << to_string(rights);
}
*this =
AdministratorRights(rights->anonymous_, rights->other_, rights->change_info_, rights->post_messages_,
rights->edit_messages_, rights->delete_messages_, rights->invite_users_, rights->ban_users_,
rights->pin_messages_, rights->add_admins_, rights->manage_call_, channel_type);
*this = AdministratorRights(rights->anonymous_, rights->other_, rights->change_info_, rights->post_messages_,
rights->edit_messages_, rights->delete_messages_, rights->invite_users_,
rights->ban_users_, rights->pin_messages_, rights->manage_topics_, rights->add_admins_,
rights->manage_call_, channel_type);
}
AdministratorRights::AdministratorRights(const td_api::object_ptr<td_api::chatAdministratorRights> &rights,
@ -43,16 +43,19 @@ AdministratorRights::AdministratorRights(const td_api::object_ptr<td_api::chatAd
*this = 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_, channel_type);
rights->can_manage_topics_, rights->can_promote_members_, rights->can_manage_video_chats_,
channel_type);
}
AdministratorRights::AdministratorRights(bool is_anonymous, bool can_manage_dialog, 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_calls, ChannelType channel_type) {
bool can_manage_topics, bool can_promote_members, bool can_manage_calls,
ChannelType channel_type) {
switch (channel_type) {
case ChannelType::Broadcast:
can_pin_messages = false;
can_manage_topics = false;
is_anonymous = false;
break;
case ChannelType::Megagroup:
@ -70,6 +73,7 @@ AdministratorRights::AdministratorRights(bool is_anonymous, bool can_manage_dial
(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) |
(static_cast<uint32>(can_manage_topics) * CAN_MANAGE_TOPICS) |
(static_cast<uint32>(can_promote_members) * CAN_PROMOTE_MEMBERS) |
(static_cast<uint32>(can_manage_calls) * CAN_MANAGE_CALLS) |
(static_cast<uint32>(is_anonymous) * IS_ANONYMOUS);
@ -104,6 +108,9 @@ telegram_api::object_ptr<telegram_api::chatAdminRights> AdministratorRights::get
if (can_pin_messages()) {
flags |= telegram_api::chatAdminRights::PIN_MESSAGES_MASK;
}
if (can_manage_topics()) {
flags |= telegram_api::chatAdminRights::MANAGE_TOPICS_MASK;
}
if (can_promote_members()) {
flags |= telegram_api::chatAdminRights::ADD_ADMINS_MASK;
}
@ -126,8 +133,8 @@ telegram_api::object_ptr<telegram_api::chatAdminRights> AdministratorRights::get
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());
can_delete_messages(), can_invite_users(), can_restrict_members(), can_pin_messages(), can_manage_topics(),
can_promote_members(), can_manage_calls(), is_anonymous());
}
bool operator==(const AdministratorRights &lhs, const AdministratorRights &rhs) {
@ -164,6 +171,9 @@ StringBuilder &operator<<(StringBuilder &string_builder, const AdministratorRigh
if (status.can_pin_messages()) {
string_builder << "(pin)";
}
if (status.can_manage_topics()) {
string_builder << "(manage_topics)";
}
if (status.can_promote_members()) {
string_builder << "(promote)";
}
@ -187,9 +197,10 @@ RestrictedRights::RestrictedRights(const tl_object_ptr<telegram_api::chatBannedR
LOG_IF(ERROR, rights->until_date_ != std::numeric_limits<int32>::max())
<< "Have until date " << rights->until_date_ << " in restricted rights";
*this = RestrictedRights(!rights->send_messages_, !rights->send_media_, !rights->send_stickers_, !rights->send_gifs_,
!rights->send_games_, !rights->send_inline_, !rights->embed_links_, !rights->send_polls_,
!rights->change_info_, !rights->invite_users_, !rights->pin_messages_);
*this =
RestrictedRights(!rights->send_messages_, !rights->send_media_, !rights->send_stickers_, !rights->send_gifs_,
!rights->send_games_, !rights->send_inline_, !rights->embed_links_, !rights->send_polls_,
!rights->change_info_, !rights->invite_users_, !rights->pin_messages_, !rights->manage_topics_);
}
RestrictedRights::RestrictedRights(const td_api::object_ptr<td_api::chatPermissions> &rights) {
@ -205,13 +216,15 @@ RestrictedRights::RestrictedRights(const td_api::object_ptr<td_api::chatPermissi
*this = RestrictedRights(can_send_messages, can_send_media, rights->can_send_other_messages_,
rights->can_send_other_messages_, rights->can_send_other_messages_,
rights->can_send_other_messages_, rights->can_add_web_page_previews_, can_send_polls,
rights->can_change_info_, rights->can_invite_users_, rights->can_pin_messages_);
rights->can_change_info_, rights->can_invite_users_, rights->can_pin_messages_,
rights->can_manage_topics_);
}
RestrictedRights::RestrictedRights(bool can_send_messages, bool can_send_media, bool can_send_stickers,
bool can_send_animations, bool can_send_games, bool can_use_inline_bots,
bool can_add_web_page_previews, bool can_send_polls,
bool can_change_info_and_settings, bool can_invite_users, bool can_pin_messages) {
bool can_change_info_and_settings, bool can_invite_users, bool can_pin_messages,
bool can_manage_topics) {
flags_ = (static_cast<uint32>(can_send_messages) * CAN_SEND_MESSAGES) |
(static_cast<uint32>(can_send_media) * CAN_SEND_MEDIA) |
(static_cast<uint32>(can_send_stickers) * CAN_SEND_STICKERS) |
@ -222,14 +235,16 @@ RestrictedRights::RestrictedRights(bool can_send_messages, bool can_send_media,
(static_cast<uint32>(can_send_polls) * CAN_SEND_POLLS) |
(static_cast<uint32>(can_change_info_and_settings) * CAN_CHANGE_INFO_AND_SETTINGS) |
(static_cast<uint32>(can_invite_users) * CAN_INVITE_USERS) |
(static_cast<uint32>(can_pin_messages) * CAN_PIN_MESSAGES);
(static_cast<uint32>(can_pin_messages) * CAN_PIN_MESSAGES) |
(static_cast<uint32>(can_manage_topics) * CAN_MANAGE_TOPICS);
}
td_api::object_ptr<td_api::chatPermissions> RestrictedRights::get_chat_permissions_object() const {
return td_api::make_object<td_api::chatPermissions>(
can_send_messages(), can_send_media(), can_send_polls(),
can_send_stickers() || can_send_animations() || can_send_games() || can_use_inline_bots(),
can_add_web_page_previews(), can_change_info_and_settings(), can_invite_users(), can_pin_messages());
can_add_web_page_previews(), can_change_info_and_settings(), can_invite_users(), can_pin_messages(),
can_manage_topics());
}
tl_object_ptr<telegram_api::chatBannedRights> RestrictedRights::get_chat_banned_rights() const {
@ -267,6 +282,9 @@ tl_object_ptr<telegram_api::chatBannedRights> RestrictedRights::get_chat_banned_
if (!can_pin_messages()) {
flags |= telegram_api::chatBannedRights::PIN_MESSAGES_MASK;
}
if (!can_manage_topics()) {
flags |= telegram_api::chatBannedRights::MANAGE_TOPICS_MASK;
}
LOG(INFO) << "Create chat banned rights " << flags;
return make_tl_object<telegram_api::chatBannedRights>(
@ -318,6 +336,9 @@ StringBuilder &operator<<(StringBuilder &string_builder, const RestrictedRights
if (!status.can_pin_messages()) {
string_builder << "(pin)";
}
if (!status.can_manage_topics()) {
string_builder << "(topics)";
}
return string_builder;
}
@ -376,16 +397,16 @@ DialogParticipantStatus DialogParticipantStatus::Banned(int32 banned_until_date)
}
DialogParticipantStatus DialogParticipantStatus::GroupAdministrator(bool is_creator) {
return Administrator(
AdministratorRights(false, true, true, false, false, true, true, true, true, false, true, ChannelType::Unknown),
string(), is_creator);
return Administrator(AdministratorRights(false, true, true, false, false, true, true, true, true, false, false, true,
ChannelType::Unknown),
string(), is_creator);
}
DialogParticipantStatus DialogParticipantStatus::ChannelAdministrator(bool is_creator, bool is_megagroup) {
auto rights = is_megagroup ? AdministratorRights(false, true, true, false, false, true, true, true, true, false,
auto rights = is_megagroup ? AdministratorRights(false, true, true, false, false, true, true, true, true, true, false,
false, ChannelType::Megagroup)
: AdministratorRights(false, true, false, true, true, true, false, true, false, false,
false, ChannelType::Broadcast);
false, false, ChannelType::Broadcast);
return Administrator(rights, string(), is_creator);
}
@ -418,7 +439,7 @@ DialogParticipantStatus::DialogParticipantStatus(bool is_member,
RestrictedRights DialogParticipantStatus::get_effective_restricted_rights() const {
return RestrictedRights(can_send_messages(), can_send_media(), can_send_stickers(), can_send_animations(),
can_send_games(), can_use_inline_bots(), can_add_web_page_previews(), can_send_polls(),
can_change_info_and_settings(), can_invite_users(), can_pin_messages());
can_change_info_and_settings(), can_invite_users(), can_pin_messages(), can_create_topics());
}
tl_object_ptr<td_api::ChatMemberStatus> DialogParticipantStatus::get_chat_member_status_object() const {

View File

@ -33,11 +33,13 @@ class AdministratorRights {
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_MANAGE_TOPICS = 1 << 11;
static constexpr uint32 IS_ANONYMOUS = 1 << 13;
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;
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_MANAGE_TOPICS |
CAN_PROMOTE_MEMBERS | CAN_MANAGE_CALLS | CAN_MANAGE_DIALOG;
uint32 flags_;
@ -57,8 +59,8 @@ class AdministratorRights {
AdministratorRights(bool is_anonymous, bool can_manage_dialog, 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_calls,
ChannelType channel_type);
bool can_restrict_members, bool can_pin_messages, bool can_manage_topics,
bool can_promote_members, bool can_manage_calls, ChannelType channel_type);
telegram_api::object_ptr<telegram_api::chatAdminRights> get_chat_admin_rights() const;
@ -96,6 +98,10 @@ class AdministratorRights {
return (flags_ & CAN_PIN_MESSAGES) != 0;
}
bool can_manage_topics() const {
return (flags_ & CAN_MANAGE_TOPICS) != 0;
}
bool can_promote_members() const {
return (flags_ & CAN_PROMOTE_MEMBERS) != 0;
}
@ -141,9 +147,10 @@ class RestrictedRights {
static constexpr uint32 CAN_CHANGE_INFO_AND_SETTINGS = 1 << 24;
static constexpr uint32 CAN_INVITE_USERS = 1 << 25;
static constexpr uint32 CAN_PIN_MESSAGES = 1 << 26;
static constexpr uint32 CAN_MANAGE_TOPICS = 1 << 12;
static constexpr uint32 ALL_ADMIN_PERMISSION_RIGHTS =
CAN_CHANGE_INFO_AND_SETTINGS | CAN_INVITE_USERS | CAN_PIN_MESSAGES;
CAN_CHANGE_INFO_AND_SETTINGS | CAN_INVITE_USERS | CAN_PIN_MESSAGES | CAN_MANAGE_TOPICS;
static constexpr uint32 ALL_RESTRICTED_RIGHTS =
CAN_SEND_MESSAGES | CAN_SEND_MEDIA | CAN_SEND_STICKERS | CAN_SEND_ANIMATIONS | CAN_SEND_GAMES |
@ -163,7 +170,8 @@ class RestrictedRights {
RestrictedRights(bool can_send_messages, bool can_send_media, bool can_send_stickers, bool can_send_animations,
bool can_send_games, bool can_use_inline_bots, bool can_add_web_page_previews, bool can_send_polls,
bool can_change_info_and_settings, bool can_invite_users, bool can_pin_messages);
bool can_change_info_and_settings, bool can_invite_users, bool can_pin_messages,
bool can_manage_topics);
td_api::object_ptr<td_api::chatPermissions> get_chat_permissions_object() const;
@ -181,6 +189,10 @@ class RestrictedRights {
return (flags_ & CAN_PIN_MESSAGES) != 0;
}
bool can_manage_topics() const {
return (flags_ & CAN_MANAGE_TOPICS) != 0;
}
bool can_send_messages() const {
return (flags_ & CAN_SEND_MESSAGES) != 0;
}
@ -235,7 +247,7 @@ bool operator!=(const RestrictedRights &lhs, const RestrictedRights &rhs);
StringBuilder &operator<<(StringBuilder &string_builder, const RestrictedRights &status);
class DialogParticipantStatus {
// only flags 11 and 12 are unused
// all flags are used
static constexpr uint32 HAS_RANK = 1 << 14;
static constexpr uint32 CAN_BE_EDITED = 1 << 15;
@ -343,6 +355,15 @@ class DialogParticipantStatus {
return get_administrator_rights().can_pin_messages() || get_restricted_rights().can_pin_messages();
}
bool can_edit_topics() const {
// topics can be edited, only if administrator was explicitly granted the right
return get_administrator_rights().can_manage_topics();
}
bool can_create_topics() const {
return get_administrator_rights().can_manage_topics() || get_restricted_rights().can_manage_topics();
}
bool can_promote_members() const {
return get_administrator_rights().can_promote_members();
}

View File

@ -90,6 +90,7 @@ static AdministratorRights get_administrator_rights(Slice rights, bool for_chann
bool can_invite_users = false;
bool can_restrict_members = false;
bool can_pin_messages = false;
bool can_manage_topics = false;
bool can_promote_members = false;
bool can_manage_calls = false;
bool is_anonymous = false;
@ -108,6 +109,8 @@ static AdministratorRights get_administrator_rights(Slice rights, bool for_chann
can_invite_users = true;
} else if (right == "pin_messages") {
can_pin_messages = true;
} else if (right == "manage_topics") {
can_manage_topics = true;
} else if (right == "promote_members") {
can_promote_members = true;
} else if (right == "manage_video_chats") {
@ -120,7 +123,7 @@ static AdministratorRights get_administrator_rights(Slice rights, bool for_chann
}
return AdministratorRights(is_anonymous, 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,
can_manage_topics, can_promote_members, can_manage_calls,
for_channel ? ChannelType::Broadcast : ChannelType::Megagroup);
}

View File

@ -33678,7 +33678,7 @@ RestrictedRights MessagesManager::get_dialog_default_permissions(DialogId dialog
case DialogType::None:
default:
UNREACHABLE();
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, false);
}
}

View File

@ -1435,10 +1435,11 @@ class CliClient final : public Actor {
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) {
bool can_manage_topics, 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);
can_restrict_members, can_pin_messages, can_manage_topics, can_promote_members, can_manage_video_chats,
is_anonymous);
}
static td_api::object_ptr<td_api::TopChatCategory> as_top_chat_category(MutableSlice category) {
@ -4340,11 +4341,12 @@ class CliClient final : public Actor {
ChatId chat_id;
string permissions;
get_args(args, chat_id, permissions);
if (permissions.size() == 8) {
if (permissions.size() == 9) {
auto &s = permissions;
send_request(td_api::make_object<td_api::setChatPermissions>(
chat_id, td_api::make_object<td_api::chatPermissions>(s[0] == '1', s[1] == '1', s[2] == '1', s[3] == '1',
s[4] == '1', s[5] == '1', s[6] == '1', s[7] == '1')));
s[4] == '1', s[5] == '1', s[6] == '1', s[7] == '1',
s[8] == '1')));
} else {
LOG(ERROR) << "Wrong permissions size, expected 8";
}
@ -4423,47 +4425,54 @@ class CliClient final : public Actor {
} else if (status_str == "anonadmin") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>(
"anon", true,
as_chat_administrator_rights(true, true, true, true, true, true, true, true, true, true, true));
as_chat_administrator_rights(true, true, true, true, true, true, true, true, true, true, true, true));
} else if (status_str == "anon") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>(
"anon", false,
as_chat_administrator_rights(false, false, false, false, false, false, false, false, false, false, true));
as_chat_administrator_rights(false, false, false, false, false, false, false, false, false, false, false,
true));
} else if (status_str == "addadmin") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>(
"anon", false,
as_chat_administrator_rights(false, false, false, false, false, false, false, false, true, false, false));
as_chat_administrator_rights(false, false, false, false, false, false, false, false, false, true, false,
false));
} else if (status_str == "calladmin") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>(
"anon", false,
as_chat_administrator_rights(false, false, false, false, false, false, false, false, false, true, false));
as_chat_administrator_rights(false, false, false, false, false, false, false, false, false, false, true,
false));
} else if (status_str == "admin") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>(
"", true, as_chat_administrator_rights(false, true, true, true, true, true, true, true, true, true, false));
"", true,
as_chat_administrator_rights(false, true, true, true, true, true, true, true, true, true, true, false));
} else if (status_str == "adminq") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>(
"title", true,
as_chat_administrator_rights(false, true, true, true, true, true, true, true, true, true, false));
as_chat_administrator_rights(false, true, true, true, true, true, true, true, true, true, true, false));
} else if (status_str == "minadmin") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>(
"", true,
as_chat_administrator_rights(true, false, false, false, false, false, false, false, false, false, false));
as_chat_administrator_rights(true, false, false, false, false, false, false, false, false, false, false,
false));
} else if (status_str == "unadmin") {
status = td_api::make_object<td_api::chatMemberStatusAdministrator>("", true, nullptr);
} else if (status_str == "rest") {
status = td_api::make_object<td_api::chatMemberStatusRestricted>(
true, static_cast<int32>(120 + std::time(nullptr)),
td_api::make_object<td_api::chatPermissions>(false, false, false, false, false, false, false, false));
td_api::make_object<td_api::chatPermissions>(false, false, false, false, false, false, false, false,
false));
} else if (status_str == "restkick") {
status = td_api::make_object<td_api::chatMemberStatusRestricted>(
false, static_cast<int32>(120 + std::time(nullptr)),
td_api::make_object<td_api::chatPermissions>(true, false, false, false, false, false, false, false));
td_api::make_object<td_api::chatPermissions>(true, false, false, false, false, false, false, false, false));
} else if (status_str == "restunkick") {
status = td_api::make_object<td_api::chatMemberStatusRestricted>(
true, static_cast<int32>(120 + std::time(nullptr)),
td_api::make_object<td_api::chatPermissions>(true, false, false, false, false, false, false, false));
td_api::make_object<td_api::chatPermissions>(true, false, false, false, false, false, false, false, false));
} else if (status_str == "unrest") {
status = td_api::make_object<td_api::chatMemberStatusRestricted>(
true, 0, td_api::make_object<td_api::chatPermissions>(true, true, true, true, true, true, true, true));
true, 0,
td_api::make_object<td_api::chatPermissions>(true, true, true, true, true, true, true, true, true));
}
if (status != nullptr) {
send_request(

View File

@ -100,11 +100,12 @@ static void parse_internal_link(const td::string &url, td::td_api::object_ptr<td
TEST(Link, parse_internal_link) {
auto 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) {
bool can_restrict_members, bool can_pin_messages, bool can_manage_topics,
bool can_promote_members, bool can_manage_video_chats, bool is_anonymous) {
return td::td_api::make_object<td::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);
can_restrict_members, can_pin_messages, can_manage_topics, can_promote_members, can_manage_video_chats,
is_anonymous);
};
auto target_chat_chosen = [](bool allow_users, bool allow_bots, bool allow_groups, bool allow_channels) {
return td::td_api::make_object<td::td_api::targetChatChosen>(allow_users, allow_bots, allow_groups, allow_channels);
@ -795,24 +796,25 @@ TEST(Link, parse_internal_link) {
parse_internal_link("tg:resolve?domain=username&startgroup=1&admin=delete_messages+anonymous",
bot_start_in_group("username", "1",
chat_administrator_rights(true, false, false, false, true, false, false, false,
false, false, true)));
false, false, false, true)));
parse_internal_link(
"tg:resolve?domain=username&startgroup&admin=manage_chat+change_info+post_messages+edit_messages+delete_messages+"
"invite_users+restrict_members+pin_messages+promote_members+manage_video_chats+anonymous",
"invite_users+restrict_members+pin_messages+manage_topics+promote_members+manage_video_chats+anonymous",
bot_start_in_group(
"username", "",
chat_administrator_rights(true, true, false, false, true, true, true, true, true, true, true)));
chat_administrator_rights(true, true, false, false, true, true, true, true, true, true, true, true)));
parse_internal_link("tg:resolve?domain=username&startchannel", public_chat("username"));
parse_internal_link("tg:resolve?domain=username&startchannel&admin=", public_chat("username"));
parse_internal_link("tg:resolve?domain=username&startchannel&admin=post_messages",
bot_add_to_channel("username", chat_administrator_rights(true, false, true, false, false, false,
true, false, false, false, false)));
parse_internal_link(
"tg:resolve?domain=username&startchannel&admin=post_messages",
bot_add_to_channel("username", chat_administrator_rights(true, false, true, false, false, false, true, false,
false, false, false, false)));
parse_internal_link(
"tg:resolve?domain=username&startchannel&admin=manage_chat+change_info+post_messages+edit_messages+delete_"
"messages+invite_users+restrict_members+pin_messages+promote_members+manage_video_chats+anonymous",
bot_add_to_channel(
"username", chat_administrator_rights(true, true, true, true, true, true, true, false, true, true, false)));
"messages+invite_users+restrict_members+pin_messages+manage_topics+promote_members+manage_video_chats+anonymous",
bot_add_to_channel("username", chat_administrator_rights(true, true, true, true, true, true, true, false, false,
true, true, false)));
parse_internal_link("t.me/username/0/a//s/as?startgroup=", bot_start_in_group("username", "", nullptr));
parse_internal_link("t.me/username/aasdas?test=1&startgroup=#12312", bot_start_in_group("username", "", nullptr));
@ -830,26 +832,27 @@ TEST(Link, parse_internal_link) {
parse_internal_link("t.me/username?startgroup=1&admin=delete_messages+anonymous",
bot_start_in_group("username", "1",
chat_administrator_rights(true, false, false, false, true, false, false, false,
false, false, true)));
false, false, false, true)));
parse_internal_link(
"t.me/"
"username?startgroup&admin=manage_chat+change_info+post_messages+edit_messages+delete_messages+invite_users+"
"restrict_members+pin_messages+promote_members+manage_video_chats+anonymous",
"restrict_members+pin_messages+manage_topics+promote_members+manage_video_chats+anonymous",
bot_start_in_group(
"username", "",
chat_administrator_rights(true, true, false, false, true, true, true, true, true, true, true)));
chat_administrator_rights(true, true, false, false, true, true, true, true, true, true, true, true)));
parse_internal_link("t.me/username?startchannel", public_chat("username"));
parse_internal_link("t.me/username?startchannel&admin=", public_chat("username"));
parse_internal_link("t.me/username?startchannel&admin=post_messages",
bot_add_to_channel("username", chat_administrator_rights(true, false, true, false, false, false,
true, false, false, false, false)));
parse_internal_link(
"t.me/username?startchannel&admin=post_messages",
bot_add_to_channel("username", chat_administrator_rights(true, false, true, false, false, false, true, false,
false, false, false, false)));
parse_internal_link(
"t.me/"
"username?startchannel&admin=manage_chat+change_info+post_messages+edit_messages+delete_messages+invite_users+"
"restrict_members+pin_messages+promote_members+manage_video_chats+anonymous",
bot_add_to_channel(
"username", chat_administrator_rights(true, true, true, true, true, true, true, false, true, true, false)));
"restrict_members+pin_messages+manage_topics+promote_members+manage_video_chats+anonymous",
bot_add_to_channel("username", chat_administrator_rights(true, true, true, true, true, true, true, false, false,
true, true, false)));
parse_internal_link("tg:resolve?domain=username&game=aasdasd", game("username", "aasdasd"));
parse_internal_link("TG://resolve?domain=username&game=", public_chat("username"));