Add story-related administrator rights.

This commit is contained in:
levlam 2023-09-04 20:24:44 +03:00
parent 08639b520a
commit 3c977a0f99
6 changed files with 128 additions and 41 deletions

View File

@ -660,8 +660,11 @@ chatPermissions can_send_basic_messages:Bool can_send_audios:Bool can_send_docum
//@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
//@can_post_stories True, if the administrator can create new channel stories, or edit and delete posted stories; applicable to channels only
//@can_edit_stories True, if the administrator can edit stories of other users, pin stories and access story archive; applicable to channels only
//@can_delete_stories True, if the administrator can delete stories of other users; applicable to channels only
//@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_manage_topics: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 can_post_stories:Bool can_edit_stories:Bool can_delete_stories:Bool is_anonymous:Bool = ChatAdministratorRights;
//@description Describes an option for buying Telegram Premium to a user

View File

@ -28,10 +28,11 @@ 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->manage_topics_, 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_,
rights->post_stories_, rights->edit_stories_, rights->delete_stories_, channel_type);
}
AdministratorRights::AdministratorRights(const td_api::object_ptr<td_api::chatAdministratorRights> &rights,
@ -44,6 +45,7 @@ AdministratorRights::AdministratorRights(const td_api::object_ptr<td_api::chatAd
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_manage_topics_, rights->can_promote_members_, rights->can_manage_video_chats_,
rights->can_post_stories_, rights->can_edit_stories_, rights->can_delete_stories_,
channel_type);
}
@ -51,6 +53,7 @@ AdministratorRights::AdministratorRights(bool is_anonymous, bool can_manage_dial
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_calls,
bool can_post_stories, bool can_edit_stories, bool can_delete_stories,
ChannelType channel_type) {
switch (channel_type) {
case ChannelType::Broadcast:
@ -61,6 +64,9 @@ AdministratorRights::AdministratorRights(bool is_anonymous, bool can_manage_dial
case ChannelType::Megagroup:
can_post_messages = false;
can_edit_messages = false;
can_post_stories = false;
can_edit_stories = false;
can_delete_stories = false;
break;
case ChannelType::Unknown:
break;
@ -76,6 +82,9 @@ AdministratorRights::AdministratorRights(bool is_anonymous, bool can_manage_dial
(static_cast<uint64>(can_manage_topics) * CAN_MANAGE_TOPICS) |
(static_cast<uint64>(can_promote_members) * CAN_PROMOTE_MEMBERS) |
(static_cast<uint64>(can_manage_calls) * CAN_MANAGE_CALLS) |
(static_cast<uint64>(can_post_stories) * CAN_POST_STORIES) |
(static_cast<uint64>(can_edit_stories) * CAN_EDIT_STORIES) |
(static_cast<uint64>(can_delete_stories) * CAN_DELETE_STORIES) |
(static_cast<uint64>(is_anonymous) * IS_ANONYMOUS);
if (flags_ != 0) {
flags_ |= CAN_MANAGE_DIALOG;
@ -120,6 +129,15 @@ telegram_api::object_ptr<telegram_api::chatAdminRights> AdministratorRights::get
if (can_manage_dialog()) {
flags |= telegram_api::chatAdminRights::OTHER_MASK;
}
if (can_post_stories()) {
flags |= telegram_api::chatAdminRights::POST_STORIES_MASK;
}
if (can_edit_stories()) {
flags |= telegram_api::chatAdminRights::EDIT_STORIES_MASK;
}
if (can_delete_stories()) {
flags |= telegram_api::chatAdminRights::DELETE_STORIES_MASK;
}
if (is_anonymous()) {
flags |= telegram_api::chatAdminRights::ANONYMOUS_MASK;
}
@ -134,7 +152,8 @@ td_api::object_ptr<td_api::chatAdministratorRights> AdministratorRights::get_cha
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_manage_topics(),
can_promote_members(), can_manage_calls(), is_anonymous());
can_promote_members(), can_manage_calls(), can_post_stories(), can_edit_stories(), can_delete_stories(),
is_anonymous());
}
bool operator==(const AdministratorRights &lhs, const AdministratorRights &rhs) {
@ -180,6 +199,15 @@ StringBuilder &operator<<(StringBuilder &string_builder, const AdministratorRigh
if (status.can_manage_calls()) {
string_builder << "(voice chat)";
}
if (status.can_post_stories()) {
string_builder << "(post story)";
}
if (status.can_edit_stories()) {
string_builder << "(edit story)";
}
if (status.can_delete_stories()) {
string_builder << "(delete story)";
}
if (status.is_anonymous()) {
string_builder << "(anonymous)";
}
@ -434,15 +462,15 @@ 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, false, true,
ChannelType::Unknown),
false, false, false, 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, true, false,
false, ChannelType::Megagroup)
false, false, false, false, ChannelType::Megagroup)
: AdministratorRights(false, true, false, true, true, true, false, true, false, false,
false, false, ChannelType::Broadcast);
false, false, true, true, true, ChannelType::Broadcast);
return Administrator(rights, string(), is_creator);
}

View File

@ -34,12 +34,16 @@ class AdministratorRights {
static constexpr uint64 CAN_MANAGE_CALLS = 1 << 9;
static constexpr uint64 CAN_MANAGE_DIALOG = 1 << 10;
static constexpr uint64 CAN_MANAGE_TOPICS = 1 << 11;
static constexpr uint64 LEGACY_CAN_SEND_MEDIA = 1 << 17;
static constexpr uint64 CAN_POST_STORIES = static_cast<uint64>(1) << 48;
static constexpr uint64 CAN_EDIT_STORIES = static_cast<uint64>(1) << 49;
static constexpr uint64 CAN_DELETE_STORIES = static_cast<uint64>(1) << 50;
static constexpr uint64 IS_ANONYMOUS = 1 << 13;
static constexpr uint64 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;
static constexpr uint64 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 | CAN_POST_STORIES | CAN_EDIT_STORIES | CAN_DELETE_STORIES;
uint64 flags_;
@ -60,7 +64,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_manage_topics,
bool can_promote_members, bool can_manage_calls, ChannelType channel_type);
bool can_promote_members, bool can_manage_calls, bool can_post_stories, bool can_edit_stories,
bool can_delete_stories, ChannelType channel_type);
telegram_api::object_ptr<telegram_api::chatAdminRights> get_chat_admin_rights() const;
@ -110,6 +115,18 @@ class AdministratorRights {
return (flags_ & CAN_MANAGE_CALLS) != 0;
}
bool can_post_stories() const {
return (flags_ & CAN_POST_STORIES) != 0;
}
bool can_edit_stories() const {
return (flags_ & CAN_EDIT_STORIES) != 0;
}
bool can_delete_stories() const {
return (flags_ & CAN_DELETE_STORIES) != 0;
}
bool is_anonymous() const {
return (flags_ & IS_ANONYMOUS) != 0;
}
@ -427,6 +444,18 @@ class DialogParticipantStatus {
return get_administrator_rights().can_manage_calls();
}
bool can_post_stories() const {
return get_administrator_rights().can_post_stories();
}
bool can_edit_stories() const {
return get_administrator_rights().can_edit_stories();
}
bool can_delete_stories() const {
return get_administrator_rights().can_delete_stories();
}
bool can_be_edited() const {
return (flags_ & CAN_BE_EDITED) != 0;
}

View File

@ -121,6 +121,9 @@ static AdministratorRights get_administrator_rights(Slice rights, bool for_chann
bool can_manage_topics = false;
bool can_promote_members = false;
bool can_manage_calls = false;
bool can_post_stories = false;
bool can_edit_stories = false;
bool can_delete_stories = false;
bool is_anonymous = false;
for (auto right : full_split(rights, ' ')) {
if (right == "change_info") {
@ -143,6 +146,12 @@ static AdministratorRights get_administrator_rights(Slice rights, bool for_chann
can_promote_members = true;
} else if (right == "manage_video_chats") {
can_manage_calls = true;
} else if (right == "post_stories") {
can_post_stories = true;
} else if (right == "edit_stories") {
can_edit_stories = true;
} else if (right == "delete_stories") {
can_delete_stories = true;
} else if (right == "anonymous") {
is_anonymous = true;
} else if (right == "manage_chat") {
@ -151,7 +160,8 @@ 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_manage_topics, can_promote_members, can_manage_calls,
can_manage_topics, can_promote_members, can_manage_calls, can_post_stories,
can_edit_stories, can_delete_stories,
for_channel ? ChannelType::Broadcast : ChannelType::Megagroup);
}
@ -187,6 +197,15 @@ static string get_admin_string(AdministratorRights rights) {
if (rights.can_manage_calls()) {
admin_rights.emplace_back("manage_video_chats");
}
if (rights.can_post_stories()) {
admin_rights.emplace_back("post_stories");
}
if (rights.can_edit_stories()) {
admin_rights.emplace_back("edit_stories");
}
if (rights.can_delete_stories()) {
admin_rights.emplace_back("delete_stories");
}
if (rights.is_anonymous()) {
admin_rights.emplace_back("anonymous");
}

View File

@ -1813,11 +1813,12 @@ 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_manage_topics, 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 can_post_stories,
bool can_edit_stories, bool can_delete_stories, 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_manage_topics, can_promote_members, can_manage_video_chats,
is_anonymous);
can_post_stories, can_edit_stories, can_delete_stories, is_anonymous);
}
static td_api::object_ptr<td_api::TopChatCategory> as_top_chat_category(MutableSlice category) {
@ -5215,35 +5216,38 @@ 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, true));
as_chat_administrator_rights(true, true, true, 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, false,
true));
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, false, true, false,
false));
false, false, 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, false, true,
false));
false, false, false, 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, true, false));
as_chat_administrator_rights(false, true, true, true, 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, true, false));
as_chat_administrator_rights(false, true, true, true, 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,
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") {

View File

@ -160,11 +160,12 @@ static void parse_internal_link(const td::string &url, td::td_api::object_ptr<td
static 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_manage_topics,
bool can_promote_members, bool can_manage_video_chats, bool is_anonymous) {
bool can_promote_members, bool can_manage_video_chats, bool can_post_stories,
bool can_edit_stories, bool can_delete_stories, 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_manage_topics, can_promote_members, can_manage_video_chats,
is_anonymous);
can_post_stories, can_edit_stories, can_delete_stories, is_anonymous);
}
static auto target_chat_chosen(bool allow_users, bool allow_bots, bool allow_groups, bool allow_channels) {
@ -974,25 +975,26 @@ TEST(Link, parse_internal_link_part3) {
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, false, true)));
false, false, false, 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+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, true)));
"invite_users+restrict_members+pin_messages+manage_topics+promote_members+manage_video_chats+post_stories+edit_"
"stories+delete_stories+anonymous",
bot_start_in_group("username", "",
chat_administrator_rights(true, true, false, false, true, true, true, true, true, true, true,
false, false, false, 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, false)));
false, false, 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+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)));
true, true, false, false, false, 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/2?test=1&startgroup=#12312", bot_start_in_group("username", "", nullptr));
@ -1010,27 +1012,29 @@ TEST(Link, parse_internal_link_part3) {
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, false, true)));
false, false, false, 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+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, true)));
"restrict_members+pin_messages+manage_topics+promote_members+manage_video_chats+post_stories+edit_stories+delete_"
"stories+anonymous",
bot_start_in_group("username", "",
chat_administrator_rights(true, true, false, false, true, true, true, true, true, true, true,
false, false, false, 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, false)));
false, false, 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+manage_topics+promote_members+manage_video_chats+anonymous",
"restrict_members+pin_messages+manage_topics+promote_members+manage_video_chats+post_stories+edit_stories+delete_"
"stories+anonymous",
bot_add_to_channel("username", chat_administrator_rights(true, true, true, true, true, true, true, false, false,
true, true, false)));
true, true, true, true, true, false)));
}
TEST(Link, parse_internal_link_part4) {