From 30f0509f71e602e6082576ec59549e968ee556ef Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 27 May 2021 01:25:11 +0300 Subject: [PATCH] Add internalLinkTypeQrCodeAuthentication. --- td/generate/scheme/td_api.tl | 5 ++++- td/telegram/LinkManager.cpp | 14 ++++++++++++++ td/telegram/LinkManager.h | 10 +++++++++- test/link.cpp | 6 ++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 2ef996d99..d8a57a8cc 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3013,11 +3013,14 @@ internalLinkTypeMessage = InternalLinkType; //@text Message draft text @contains_link True, if the first line of the text contains a link. If true, the input field needs to be focused and the text after the link should be selected internalLinkTypeMessageDraft text:formattedText contains_link:Bool = InternalLinkType; +//@description The link can be used to login the current user on another device, but it must be scanned from QR-code using in-app camera. An alert similar to +//-"This code can be used to allow someone to log in to your Telegram account. To confirm Telegram login, please go to Settings > Devices > Scan QR and scan the code" needs to be shown +internalLinkTypeQrCodeAuthentication = InternalLinkType; + //@description The link is an unknown tg: link. Call getDeepLinkInfo to process the link internalLinkTypeUnknownDeepLink = InternalLinkType; - //@description Contains an HTTPS link to a message in a supergroup or channel @link Message link @is_public True, if the link will work for non-members of the chat messageLink link:string is_public:Bool = MessageLink; diff --git a/td/telegram/LinkManager.cpp b/td/telegram/LinkManager.cpp index 6677cf720..8650e6eba 100644 --- a/td/telegram/LinkManager.cpp +++ b/td/telegram/LinkManager.cpp @@ -83,6 +83,16 @@ class LinkManager::InternalLinkMessageDraft : public InternalLink { } }; +class LinkManager::InternalLinkQrCodeAuthentication : public InternalLink { + td_api::object_ptr get_internal_link_type_object() const final { + return td_api::make_object(); + } + + InternalLinkType get_type() const final { + return InternalLinkType::QrCodeAuthentication; + } +}; + class LinkManager::InternalLinkUnknownDeepLink : public InternalLink { td_api::object_ptr get_internal_link_type_object() const final { return td_api::make_object(); @@ -407,6 +417,10 @@ unique_ptr LinkManager::parse_tg_link_query(Slice que if (has_arg("code")) { return td::make_unique(get_arg("code")); } + // login?token=abacaba + if (has_arg("token")) { + return td::make_unique(); + } } else if (path.size() == 1 && path[0] == "privatepost") { // privatepost?channel=123456789&msg_id=12345 if (has_arg("channel") && has_arg("msg_id")) { diff --git a/td/telegram/LinkManager.h b/td/telegram/LinkManager.h index a806a29c3..862f61d2d 100644 --- a/td/telegram/LinkManager.h +++ b/td/telegram/LinkManager.h @@ -33,7 +33,14 @@ class LinkManager : public Actor { LinkManager &operator=(LinkManager &&) = delete; ~LinkManager() override; - enum class InternalLinkType : int32 { AuthenticationCode, Background, Message, MessageDraft, UnknownDeepLink }; + enum class InternalLinkType : int32 { + AuthenticationCode, + Background, + Message, + MessageDraft, + QrCodeAuthentication, + UnknownDeepLink + }; class InternalLink { public: @@ -81,6 +88,7 @@ class LinkManager : public Actor { class InternalLinkBackground; class InternalLinkMessage; class InternalLinkMessageDraft; + class InternalLinkQrCodeAuthentication; class InternalLinkUnknownDeepLink; static unique_ptr parse_tg_link_query(Slice query); diff --git a/test/link.cpp b/test/link.cpp index 514c09730..26e5c14aa 100644 --- a/test/link.cpp +++ b/test/link.cpp @@ -78,6 +78,9 @@ TEST(Link, parse_internal_link) { formatted_text->text_ = std::move(text); return td::td_api::make_object(std::move(formatted_text), contains_url); }; + auto qr_code_authentication = []() { + return td::td_api::make_object(); + }; auto unknown_deep_link = [] { return td::td_api::make_object(); }; @@ -241,4 +244,7 @@ TEST(Link, parse_internal_link) { parse_internal_link("t.me/login/12345678901", authentication_code("12345678901")); parse_internal_link("t.me/login/123456", authentication_code("123456")); parse_internal_link("t.me/login/123456/123123/12/31/a/s//21w/?asdas#test", authentication_code("123456")); + + parse_internal_link("tg:login?token=abacaba", qr_code_authentication()); + parse_internal_link("tg:login?token=", qr_code_authentication()); }