Add internalLinkTypeQrCodeAuthentication.

This commit is contained in:
levlam 2021-05-27 01:25:11 +03:00
parent 38d71ca7e0
commit 30f0509f71
4 changed files with 33 additions and 2 deletions

View File

@ -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;

View File

@ -83,6 +83,16 @@ class LinkManager::InternalLinkMessageDraft : public InternalLink {
}
};
class LinkManager::InternalLinkQrCodeAuthentication : public InternalLink {
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeQrCodeAuthentication>();
}
InternalLinkType get_type() const final {
return InternalLinkType::QrCodeAuthentication;
}
};
class LinkManager::InternalLinkUnknownDeepLink : public InternalLink {
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeUnknownDeepLink>();
@ -407,6 +417,10 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
if (has_arg("code")) {
return td::make_unique<InternalLinkAuthenticationCode>(get_arg("code"));
}
// login?token=abacaba
if (has_arg("token")) {
return td::make_unique<InternalLinkQrCodeAuthentication>();
}
} else if (path.size() == 1 && path[0] == "privatepost") {
// privatepost?channel=123456789&msg_id=12345
if (has_arg("channel") && has_arg("msg_id")) {

View File

@ -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<InternalLink> parse_tg_link_query(Slice query);

View File

@ -78,6 +78,9 @@ TEST(Link, parse_internal_link) {
formatted_text->text_ = std::move(text);
return td::td_api::make_object<td::td_api::internalLinkTypeMessageDraft>(std::move(formatted_text), contains_url);
};
auto qr_code_authentication = []() {
return td::td_api::make_object<td::td_api::internalLinkTypeQrCodeAuthentication>();
};
auto unknown_deep_link = [] {
return td::td_api::make_object<td::td_api::internalLinkTypeUnknownDeepLink>();
};
@ -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());
}