Add internalLinkTypeUserToken.

This commit is contained in:
levlam 2022-12-01 17:42:57 +03:00
parent 6977ac94ed
commit 02ff843bbb
4 changed files with 49 additions and 0 deletions

View File

@ -3924,6 +3924,9 @@ internalLinkTypeUnsupportedProxy = InternalLinkType;
//@description The link is a link to a user by its phone number. Call searchUserByPhoneNumber with the given phone number to process the link @phone_number Phone number of the user //@description The link is a link to a user by its phone number. Call searchUserByPhoneNumber with the given phone number to process the link @phone_number Phone number of the user
internalLinkTypeUserPhoneNumber phone_number:string = InternalLinkType; internalLinkTypeUserPhoneNumber phone_number:string = InternalLinkType;
//@description The link is a link to a user by a temporary token. Call searchUserByToken with the given token to process the link @token The token
internalLinkTypeUserToken token:string = InternalLinkType;
//@description The link is a link to a video chat. Call searchPublicChat with the given chat username, and then joinGroupCall with the given invite hash to process the link //@description The link is a link to a video chat. Call searchPublicChat with the given chat username, and then joinGroupCall with the given invite hash to process the link
//@chat_username Username of the chat with the video chat @invite_hash If non-empty, invite hash to be used to join the video chat without being muted by administrators //@chat_username Username of the chat with the video chat @invite_hash If non-empty, invite hash to be used to join the video chat without being muted by administrators
//@is_live_stream True, if the video chat is expected to be a live stream in a channel or a broadcast group //@is_live_stream True, if the video chat is expected to be a live stream in a channel or a broadcast group

View File

@ -551,6 +551,18 @@ class LinkManager::InternalLinkUserPhoneNumber final : public InternalLink {
} }
}; };
class LinkManager::InternalLinkUserToken final : public InternalLink {
string token_;
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeUserToken>(token_);
}
public:
explicit InternalLinkUserToken(string token) : token_(std::move(token)) {
}
};
class LinkManager::InternalLinkVoiceChat final : public InternalLink { class LinkManager::InternalLinkVoiceChat final : public InternalLink {
string dialog_username_; string dialog_username_;
string invite_hash_; string invite_hash_;
@ -1084,6 +1096,11 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
// resolve?phone=12345 // resolve?phone=12345
return std::move(user_link); return std::move(user_link);
} }
} else if (path.size() == 1 && path[0] == "contact") {
// contact?token=<token>
if (has_arg("token")) {
return td::make_unique<InternalLinkUserToken>(get_arg("token"));
}
} else if (path.size() == 1 && path[0] == "login") { } else if (path.size() == 1 && path[0] == "login") {
// login?code=123456 // login?code=123456
if (has_arg("code")) { if (has_arg("code")) {
@ -1282,6 +1299,11 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
<< url_encode(get_url_query_hash(false, url_query))); << url_encode(get_url_query_hash(false, url_query)));
} }
} }
} else if (path[0] == "contact") {
if (path.size() >= 2 && !path[1].empty()) {
// /contact/<token>
return td::make_unique<InternalLinkUserToken>(path[1]);
}
} else if (path[0] == "addstickers" || path[0] == "addemoji") { } else if (path[0] == "addstickers" || path[0] == "addemoji") {
if (path.size() >= 2 && !path[1].empty()) { if (path.size() >= 2 && !path[1].empty()) {
// /addstickers/<name> // /addstickers/<name>

View File

@ -133,6 +133,7 @@ class LinkManager final : public Actor {
class InternalLinkUnknownDeepLink; class InternalLinkUnknownDeepLink;
class InternalLinkUnsupportedProxy; class InternalLinkUnsupportedProxy;
class InternalLinkUserPhoneNumber; class InternalLinkUserPhoneNumber;
class InternalLinkUserToken;
class InternalLinkVoiceChat; class InternalLinkVoiceChat;
enum class LinkType : int32 { External, TMe, Tg, Telegraph }; enum class LinkType : int32 { External, TMe, Tg, Telegraph };

View File

@ -232,6 +232,9 @@ TEST(Link, parse_internal_link) {
auto user_phone_number = [](const td::string &phone_number) { auto user_phone_number = [](const td::string &phone_number) {
return td::td_api::make_object<td::td_api::internalLinkTypeUserPhoneNumber>(phone_number); return td::td_api::make_object<td::td_api::internalLinkTypeUserPhoneNumber>(phone_number);
}; };
auto user_token = [](const td::string &token) {
return td::td_api::make_object<td::td_api::internalLinkTypeUserToken>(token);
};
auto video_chat = [](const td::string &chat_username, const td::string &invite_hash, bool is_live_stream) { auto video_chat = [](const td::string &chat_username, const td::string &invite_hash, bool is_live_stream) {
return td::td_api::make_object<td::td_api::internalLinkTypeVideoChat>(chat_username, invite_hash, is_live_stream); return td::td_api::make_object<td::td_api::internalLinkTypeVideoChat>(chat_username, invite_hash, is_live_stream);
}; };
@ -318,6 +321,20 @@ TEST(Link, parse_internal_link) {
parse_internal_link("tg:resolve?phone=+123", unknown_deep_link("tg://resolve?phone=+123")); parse_internal_link("tg:resolve?phone=+123", unknown_deep_link("tg://resolve?phone=+123"));
parse_internal_link("tg:resolve?phone=123456 ", unknown_deep_link("tg://resolve?phone=123456 ")); parse_internal_link("tg:resolve?phone=123456 ", unknown_deep_link("tg://resolve?phone=123456 "));
parse_internal_link("tg:contact?token=1", user_token("1"));
parse_internal_link("tg:contact?token=123456", user_token("123456"));
parse_internal_link("tg:contact?token=123456&startattach", user_token("123456"));
parse_internal_link("tg:contact?token=123456&startattach=123", user_token("123456"));
parse_internal_link("tg:contact?token=123456&attach=", user_token("123456"));
parse_internal_link("tg:contact?token=123456&attach=&startattach", user_token("123456"));
parse_internal_link("tg:contact?token=123456&attach=&startattach=123", user_token("123456"));
parse_internal_link("tg:contact?token=01234567890123456789012345678912",
user_token("01234567890123456789012345678912"));
parse_internal_link("tg:contact?token=012345678901234567890123456789123",
user_token("012345678901234567890123456789123"));
parse_internal_link("tg:contact?token=", unknown_deep_link("tg://contact?token="));
parse_internal_link("tg:contact?token=+123", user_token(" 123"));
parse_internal_link("t.me/username/12345?single", message("tg:resolve?domain=username&post=12345&single")); parse_internal_link("t.me/username/12345?single", message("tg:resolve?domain=username&post=12345&single"));
parse_internal_link("t.me/username/12345?asdasd", message("tg:resolve?domain=username&post=12345")); parse_internal_link("t.me/username/12345?asdasd", message("tg:resolve?domain=username&post=12345"));
parse_internal_link("t.me/username/12345", message("tg:resolve?domain=username&post=12345")); parse_internal_link("t.me/username/12345", message("tg:resolve?domain=username&post=12345"));
@ -573,6 +590,12 @@ TEST(Link, parse_internal_link) {
parse_internal_link("t.me/+123456?attach=bot&startattach=1", parse_internal_link("t.me/+123456?attach=bot&startattach=1",
attachment_menu_bot(nullptr, user_phone_number("123456"), "bot", "1")); attachment_menu_bot(nullptr, user_phone_number("123456"), "bot", "1"));
parse_internal_link("t.me/contact/startattach/adasd", user_token("startattach"));
parse_internal_link("t.me/contact/startattach", user_token("startattach"));
parse_internal_link("t.me/contact/startattach=1", user_token("startattach=1"));
parse_internal_link("t.me/contact/", nullptr);
parse_internal_link("t.me/contact/?attach=&startattach", nullptr);
parse_internal_link("tg:join?invite=abcdef", chat_invite("abcdef")); parse_internal_link("tg:join?invite=abcdef", chat_invite("abcdef"));
parse_internal_link("tg:join?invite=abc%20def", chat_invite("abc%20def")); parse_internal_link("tg:join?invite=abc%20def", chat_invite("abc%20def"));
parse_internal_link("tg://join?invite=abc%30def", chat_invite("abc0def")); parse_internal_link("tg://join?invite=abc%30def", chat_invite("abc0def"));