Add helper for td_api::chatAdministratorRights creation.

This commit is contained in:
levlam 2022-07-04 18:38:34 +03:00
parent d489014350
commit c50e05db27

View File

@ -95,6 +95,14 @@ 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) {
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);
};
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);
};
@ -734,29 +742,27 @@ TEST(Link, parse_internal_link) {
parse_internal_link("tg:resolve?domain=username&startgroup&admin=asdas", bot_start_in_group("username", "", nullptr));
parse_internal_link("tg:resolve?domain=username&startgroup&admin=post_messages",
bot_start_in_group("username", "", nullptr));
parse_internal_link(
"tg:resolve?domain=username&startgroup=1&admin=delete_messages+anonymous",
bot_start_in_group("username", "1",
td::td_api::make_object<td::td_api::chatAdministratorRights>(
true, false, false, false, true, false, false, false, false, false, true)));
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)));
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",
bot_start_in_group("username", "",
td::td_api::make_object<td::td_api::chatAdministratorRights>(
true, true, false, false, true, true, true, true, true, true, true)));
bot_start_in_group(
"username", "",
chat_administrator_rights(true, true, false, false, 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", td::td_api::make_object<td::td_api::chatAdministratorRights>(
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)));
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", td::td_api::make_object<td::td_api::chatAdministratorRights>(
true, true, true, true, true, true, true, false, true, true, false)));
bot_add_to_channel(
"username", chat_administrator_rights(true, true, true, true, true, true, true, 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));
@ -771,31 +777,29 @@ TEST(Link, parse_internal_link) {
parse_internal_link("t.me/username?startgroup", bot_start_in_group("username", "", nullptr));
parse_internal_link("t.me/username?startgroup&admin=asdas", bot_start_in_group("username", "", nullptr));
parse_internal_link("t.me/username?startgroup&admin=post_messages", bot_start_in_group("username", "", nullptr));
parse_internal_link(
"t.me/username?startgroup=1&admin=delete_messages+anonymous",
bot_start_in_group("username", "1",
td::td_api::make_object<td::td_api::chatAdministratorRights>(
true, false, false, false, true, false, false, false, false, false, true)));
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)));
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",
bot_start_in_group("username", "",
td::td_api::make_object<td::td_api::chatAdministratorRights>(
true, true, false, false, true, true, true, true, true, true, true)));
bot_start_in_group(
"username", "",
chat_administrator_rights(true, true, false, false, 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", td::td_api::make_object<td::td_api::chatAdministratorRights>(
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)));
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", td::td_api::make_object<td::td_api::chatAdministratorRights>(
true, true, true, true, true, true, true, false, true, true, false)));
bot_add_to_channel(
"username", chat_administrator_rights(true, true, true, true, true, true, true, 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"));