From 5c7f842f7207751787fa3a09b21371c869c1f647 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 1 Jun 2022 18:35:34 +0300 Subject: [PATCH] Actually support targetChatChosen. --- td/telegram/LinkManager.cpp | 38 +++++++++++++++++++++++++++++-------- test/link.cpp | 32 +++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/td/telegram/LinkManager.cpp b/td/telegram/LinkManager.cpp index db0f02b33..c4e406343 100644 --- a/td/telegram/LinkManager.cpp +++ b/td/telegram/LinkManager.cpp @@ -147,6 +147,28 @@ static AdministratorRights get_administrator_rights(Slice rights, bool for_chann for_channel ? ChannelType::Broadcast : ChannelType::Megagroup); } +td_api::object_ptr get_target_chat_chosen(Slice chat_types) { + bool allow_users = false; + bool allow_bots = false; + bool allow_groups = false; + bool allow_channels = false; + for (auto chat_type : full_split(chat_types, ' ')) { + if (chat_type == "users") { + allow_users = true; + } else if (chat_type == "bots") { + allow_bots = true; + } else if (chat_type == "groups") { + allow_groups = true; + } else if (chat_type == "channels") { + allow_channels = true; + } + } + if (!allow_users && !allow_bots && !allow_groups && !allow_channels) { + return nullptr; + } + return td_api::make_object(allow_users, allow_bots, allow_groups, allow_channels); +} + class LinkManager::InternalLinkActiveSessions final : public InternalLink { td_api::object_ptr get_internal_link_type_object() const final { return td_api::make_object(); @@ -1003,10 +1025,10 @@ unique_ptr LinkManager::parse_tg_link_query(Slice que nullptr, td::make_unique(std::move(username)), url_query.get_arg("attach").str(), url_query.get_arg("startattach")); } else if (url_query.has_arg("startattach")) { - // resolve?domain=&startattach - // resolve?domain=&startattach= - return td::make_unique(nullptr, nullptr, std::move(username), - url_query.get_arg("startattach")); + // resolve?domain=&startattach&choose=users+bots+groups+channels + // resolve?domain=&startattach=&choose=users+bots+groups+channels + return td::make_unique(get_target_chat_chosen(url_query.get_arg("choose")), nullptr, + std::move(username), url_query.get_arg("startattach")); } if (username == "telegrampassport") { // resolve?domain=telegrampassport&bot_id=&scope=&public_key=&nonce= @@ -1330,10 +1352,10 @@ unique_ptr LinkManager::parse_t_me_link_query(Slice q nullptr, td::make_unique(std::move(username)), url_query.get_arg("attach").str(), url_query.get_arg("startattach")); } else if (url_query.has_arg("startattach")) { - // /?startattach - // /?startattach= - return td::make_unique(nullptr, nullptr, std::move(username), - url_query.get_arg("startattach")); + // /?startattach&choose=users+bots+groups+channels + // /?startattach=&choose=users+bots+groups+channels + return td::make_unique(get_target_chat_chosen(url_query.get_arg("choose")), nullptr, + std::move(username), url_query.get_arg("startattach")); } // / diff --git a/test/link.cpp b/test/link.cpp index de45de17c..af4338745 100644 --- a/test/link.cpp +++ b/test/link.cpp @@ -95,6 +95,10 @@ static void parse_internal_link(const td::string &url, td::td_api::object_ptr(allow_users, allow_bots, allow_groups, allow_channels); + }; + auto active_sessions = [] { return td::td_api::make_object(); }; @@ -254,6 +258,18 @@ TEST(Link, parse_internal_link) { parse_internal_link("tg:resolve?domain=telegram&startattach", attachment_menu_bot(nullptr, nullptr, "telegram", "")); parse_internal_link("tg:resolve?domain=telegram&startattach=1", attachment_menu_bot(nullptr, nullptr, "telegram", "1")); + parse_internal_link("tg:resolve?domain=telegram&startattach=1&choose=cats+dogs", + attachment_menu_bot(nullptr, nullptr, "telegram", "1")); + parse_internal_link("tg:resolve?domain=telegram&startattach=1&choose=users", + attachment_menu_bot(target_chat_chosen(true, false, false, false), nullptr, "telegram", "1")); + parse_internal_link("tg:resolve?domain=telegram&startattach=1&choose=bots", + attachment_menu_bot(target_chat_chosen(false, true, false, false), nullptr, "telegram", "1")); + parse_internal_link("tg:resolve?domain=telegram&startattach=1&choose=groups", + attachment_menu_bot(target_chat_chosen(false, false, true, false), nullptr, "telegram", "1")); + parse_internal_link("tg:resolve?domain=telegram&startattach=1&choose=channels", + attachment_menu_bot(target_chat_chosen(false, false, false, true), nullptr, "telegram", "1")); + parse_internal_link("tg:resolve?domain=telegram&startattach=1&choose=users+channels", + attachment_menu_bot(target_chat_chosen(true, false, false, true), nullptr, "telegram", "1")); parse_internal_link("tg:resolve?domain=telegram&attach=&startattach", attachment_menu_bot(nullptr, nullptr, "telegram", "")); parse_internal_link("tg:resolve?domain=telegram&attach=&startattach=1", @@ -272,7 +288,7 @@ TEST(Link, parse_internal_link) { parse_internal_link("tg:resolve?phone=123456&attach=&startattach=123", user_phone_number("123456")); parse_internal_link("tg:resolve?phone=123456&attach=test", attachment_menu_bot(nullptr, user_phone_number("123456"), "test", "")); - parse_internal_link("tg:resolve?phone=123456&attach=test&startattach", + parse_internal_link("tg:resolve?phone=123456&attach=test&startattach&choose=users", attachment_menu_bot(nullptr, user_phone_number("123456"), "test", "")); parse_internal_link("tg:resolve?phone=123456&attach=test&startattach=123", attachment_menu_bot(nullptr, user_phone_number("123456"), "test", "123")); @@ -302,13 +318,25 @@ TEST(Link, parse_internal_link) { parse_internal_link("https://telegram.dog/telegram/?single", public_chat("telegram")); parse_internal_link("t.me/username?startattach", attachment_menu_bot(nullptr, nullptr, "username", "")); parse_internal_link("t.me/username?startattach=1", attachment_menu_bot(nullptr, nullptr, "username", "1")); + parse_internal_link("t.me/username?startattach=1&choose=cats+dogs", + attachment_menu_bot(nullptr, nullptr, "username", "1")); + parse_internal_link("t.me/username?startattach=1&choose=users", + attachment_menu_bot(target_chat_chosen(true, false, false, false), nullptr, "username", "1")); + parse_internal_link("t.me/username?startattach=1&choose=bots", + attachment_menu_bot(target_chat_chosen(false, true, false, false), nullptr, "username", "1")); + parse_internal_link("t.me/username?startattach=1&choose=groups", + attachment_menu_bot(target_chat_chosen(false, false, true, false), nullptr, "username", "1")); + parse_internal_link("t.me/username?startattach=1&choose=channels", + attachment_menu_bot(target_chat_chosen(false, false, false, true), nullptr, "username", "1")); + parse_internal_link("t.me/username?startattach=1&choose=bots+groups", + attachment_menu_bot(target_chat_chosen(false, true, true, false), nullptr, "username", "1")); parse_internal_link("t.me/username?attach=", public_chat("username")); parse_internal_link("t.me/username?attach=&startattach", attachment_menu_bot(nullptr, nullptr, "username", "")); parse_internal_link("t.me/username?attach=&startattach=1", attachment_menu_bot(nullptr, nullptr, "username", "1")); parse_internal_link("t.me/username?attach=bot", attachment_menu_bot(nullptr, public_chat("username"), "bot", "")); parse_internal_link("t.me/username?attach=bot&startattach", attachment_menu_bot(nullptr, public_chat("username"), "bot", "")); - parse_internal_link("t.me/username?attach=bot&startattach=1", + parse_internal_link("t.me/username?attach=bot&startattach=1&choose=users", attachment_menu_bot(nullptr, public_chat("username"), "bot", "1")); parse_internal_link("tg:privatepost?domain=username/12345&single",