Add internalLinkTypePhoneNumberConfirmation.

This commit is contained in:
levlam 2021-05-28 18:17:14 +03:00
parent feb01a71bb
commit cd95e84990
4 changed files with 74 additions and 16 deletions

View File

@ -3016,6 +3016,10 @@ 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 //@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; internalLinkTypeMessageDraft text:formattedText contains_link:Bool = InternalLinkType;
//@description The link can be used to confirm ownership of a phone number to prevent account deletion. Call sendPhoneNumberConfirmationCode with the given hash and phone number to process the link
//@hash Hash value from the link @phone_number Phone number value from the link
internalLinkTypePhoneNumberConfirmation hash:string phone_number:string = 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 //@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 //-"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; internalLinkTypeQrCodeAuthentication = InternalLinkType;
@ -5212,8 +5216,7 @@ getPassportAuthorizationFormAvailableElements autorization_form_id:int32 passwor
sendPassportAuthorizationForm autorization_form_id:int32 types:vector<PassportElementType> = Ok; sendPassportAuthorizationForm autorization_form_id:int32 types:vector<PassportElementType> = Ok;
//@description Sends phone number confirmation code. Should be called when user presses "https://t.me/confirmphone?phone=*******&hash=**********" or "tg://confirmphone?phone=*******&hash=**********" link @hash Value of the "hash" parameter from the link //@description Sends phone number confirmation code to handle links of the type internalLinkTypePhoneNumberConfirmation @hash Hash value from the link @phone_number Phone number value from the link @settings Settings for the authentication of the user's phone number
//@phone_number Value of the "phone" parameter from the link @settings Settings for the authentication of the user's phone number
sendPhoneNumberConfirmationCode hash:string phone_number:string settings:phoneNumberAuthenticationSettings = AuthenticationCodeInfo; sendPhoneNumberConfirmationCode hash:string phone_number:string settings:phoneNumberAuthenticationSettings = AuthenticationCodeInfo;
//@description Resends phone number confirmation code //@description Resends phone number confirmation code

View File

@ -55,6 +55,24 @@ class LinkManager::InternalLinkBackground : public InternalLink {
} }
}; };
class LinkManager::InternalLinkConfirmPhone : public InternalLink {
string hash_;
string phone_number_;
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypePhoneNumberConfirmation>(hash_, phone_number_);
}
InternalLinkType get_type() const final {
return InternalLinkType::ConfirmPhone;
}
public:
InternalLinkConfirmPhone(string hash, string phone_number)
: hash_(std::move(hash)), phone_number_(std::move(phone_number)) {
}
};
class LinkManager::InternalLinkDialogInvite : public InternalLink { class LinkManager::InternalLinkDialogInvite : public InternalLink {
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final { td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeChatInvite>(); return td_api::make_object<td_api::internalLinkTypeChatInvite>();
@ -426,9 +444,12 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
auto copy_arg = [&](Slice name) { auto copy_arg = [&](Slice name) {
return CopyArg(name, &url_query, &is_first_arg); return CopyArg(name, &url_query, &is_first_arg);
}; };
auto get_arg = [&](Slice name) { auto pass_arg = [&](Slice name) {
return url_encode(url_query.get_arg(name)); return url_encode(url_query.get_arg(name));
}; };
auto get_arg = [&](Slice name) {
return url_query.get_arg(name).str();
};
auto has_arg = [&](Slice name) { auto has_arg = [&](Slice name) {
return !url_query.get_arg(name).empty(); return !url_query.get_arg(name).empty();
}; };
@ -457,6 +478,11 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
if (has_arg("set")) { if (has_arg("set")) {
return td::make_unique<InternalLinkStickerSet>(get_arg("set")); return td::make_unique<InternalLinkStickerSet>(get_arg("set"));
} }
} else if (path.size() == 1 && path[0] == "confirmphone") {
if (has_arg("hash") && has_arg("phone")) {
// confirmphone?phone=<phone>&hash=<hash>
return td::make_unique<InternalLinkConfirmPhone>(get_arg("hash"), get_arg("phone"));
}
} else if (path.size() == 1 && path[0] == "privatepost") { } else if (path.size() == 1 && path[0] == "privatepost") {
// privatepost?channel=123456789&msg_id=12345 // privatepost?channel=123456789&msg_id=12345
if (has_arg("channel") && has_arg("msg_id")) { if (has_arg("channel") && has_arg("msg_id")) {
@ -469,20 +495,20 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
// bg?slug=<background_name>&mode=blur+motion // bg?slug=<background_name>&mode=blur+motion
// bg?slug=<pattern_name>&intensity=...&bg_color=...&mode=blur+motion // bg?slug=<pattern_name>&intensity=...&bg_color=...&mode=blur+motion
if (has_arg("color")) { if (has_arg("color")) {
return td::make_unique<InternalLinkBackground>(get_arg("color")); return td::make_unique<InternalLinkBackground>(pass_arg("color"));
} }
if (has_arg("gradient")) { if (has_arg("gradient")) {
return td::make_unique<InternalLinkBackground>(PSTRING() << get_arg("gradient") << copy_arg("rotation")); return td::make_unique<InternalLinkBackground>(PSTRING() << pass_arg("gradient") << copy_arg("rotation"));
} }
if (has_arg("slug")) { if (has_arg("slug")) {
return td::make_unique<InternalLinkBackground>(PSTRING() return td::make_unique<InternalLinkBackground>(PSTRING()
<< get_arg("slug") << copy_arg("mode") << copy_arg("intensity") << pass_arg("slug") << copy_arg("mode") << copy_arg("intensity")
<< copy_arg("bg_color") << copy_arg("rotation")); << copy_arg("bg_color") << copy_arg("rotation"));
} }
} else if (path.size() == 1 && (path[0] == "share" || path[0] == "msg" || path[0] == "msg_url")) { } else if (path.size() == 1 && (path[0] == "share" || path[0] == "msg" || path[0] == "msg_url")) {
// msg_url?url=<url> // msg_url?url=<url>
// msg_url?url=<url>&text=<text> // msg_url?url=<url>&text=<text>
return get_internal_link_message_draft(url_query.get_arg("url"), url_query.get_arg("text")); return get_internal_link_message_draft(get_arg("url"), get_arg("text"));
} }
if (!path.empty()) { if (!path.empty()) {
return td::make_unique<InternalLinkUnknownDeepLink>(); return td::make_unique<InternalLinkUnknownDeepLink>();
@ -502,8 +528,12 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
auto copy_arg = [&](Slice name) { auto copy_arg = [&](Slice name) {
return CopyArg(name, &url_query, &is_first_arg); return CopyArg(name, &url_query, &is_first_arg);
}; };
auto get_arg = [&](Slice name) { auto get_arg = [&](Slice name) {
return url_encode(url_query.get_arg(name)); return url_query.get_arg(name).str();
};
auto has_arg = [&](Slice name) {
return !url_query.get_arg(name).empty();
}; };
if (path[0] == "c") { if (path[0] == "c") {
@ -526,6 +556,11 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
// /addstickers/<name> // /addstickers/<name>
return td::make_unique<InternalLinkStickerSet>(path[1]); return td::make_unique<InternalLinkStickerSet>(path[1]);
} }
} else if (path[0] == "confirmphone") {
if (has_arg("hash") && has_arg("phone")) {
// /confirmphone?phone=<phone>&hash=<hash>
return td::make_unique<InternalLinkConfirmPhone>(get_arg("hash"), get_arg("phone"));
}
} else if (path[0][0] == ' ' || path[0][0] == '+') { } else if (path[0][0] == ' ' || path[0][0] == '+') {
if (path[0].size() >= 2) { if (path[0].size() >= 2) {
// /+<link> // /+<link>
@ -546,7 +581,7 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
if (!(path.size() > 1 && (path[1] == "bookmarklet" || path[1] == "embed"))) { if (!(path.size() > 1 && (path[1] == "bookmarklet" || path[1] == "embed"))) {
// /share?url=<url> // /share?url=<url>
// /share/url?url=<url>&text=<text> // /share/url?url=<url>&text=<text>
return get_internal_link_message_draft(url_query.get_arg("url"), url_query.get_arg("text")); return get_internal_link_message_draft(get_arg("url"), get_arg("text"));
} }
} else { } else {
if (path.size() >= 2 && to_integer<int64>(path[1]) > 0) { if (path.size() >= 2 && to_integer<int64>(path[1]) > 0) {

View File

@ -37,6 +37,7 @@ class LinkManager : public Actor {
enum class InternalLinkType : int32 { enum class InternalLinkType : int32 {
AuthenticationCode, AuthenticationCode,
Background, Background,
ConfirmPhone,
DialogInvite, DialogInvite,
Message, Message,
MessageDraft, MessageDraft,
@ -85,6 +86,7 @@ class LinkManager : public Actor {
class InternalLinkAuthenticationCode; class InternalLinkAuthenticationCode;
class InternalLinkBackground; class InternalLinkBackground;
class InternalLinkConfirmPhone;
class InternalLinkDialogInvite; class InternalLinkDialogInvite;
class InternalLinkMessage; class InternalLinkMessage;
class InternalLinkMessageDraft; class InternalLinkMessageDraft;

View File

@ -81,6 +81,9 @@ TEST(Link, parse_internal_link) {
formatted_text->text_ = std::move(text); formatted_text->text_ = std::move(text);
return td::td_api::make_object<td::td_api::internalLinkTypeMessageDraft>(std::move(formatted_text), contains_url); return td::td_api::make_object<td::td_api::internalLinkTypeMessageDraft>(std::move(formatted_text), contains_url);
}; };
auto phone_number_confirmation = [](td::string hash, td::string phone_number) {
return td::td_api::make_object<td::td_api::internalLinkTypePhoneNumberConfirmation>(hash, phone_number);
};
auto qr_code_authentication = []() { auto qr_code_authentication = []() {
return td::td_api::make_object<td::td_api::internalLinkTypeQrCodeAuthentication>(); return td::td_api::make_object<td::td_api::internalLinkTypeQrCodeAuthentication>();
}; };
@ -293,13 +296,28 @@ TEST(Link, parse_internal_link) {
parse_internal_link("t.me/addstickers?/abcdef", nullptr); parse_internal_link("t.me/addstickers?/abcdef", nullptr);
parse_internal_link("t.me/addstickers/?abcdef", nullptr); parse_internal_link("t.me/addstickers/?abcdef", nullptr);
parse_internal_link("t.me/addstickers/#abcdef", nullptr); parse_internal_link("t.me/addstickers/#abcdef", nullptr);
parse_internal_link("t.me/addstickers/abacaba", sticker_set()); parse_internal_link("t.me/addstickers/abacaba", sticker_set("abacaba"));
parse_internal_link("t.me/addstickers/aba%20aba", sticker_set()); parse_internal_link("t.me/addstickers/aba%20aba", sticker_set("aba aba"));
parse_internal_link("t.me/addstickers/123456a", sticker_set()); parse_internal_link("t.me/addstickers/123456a", sticker_set("123456a"));
parse_internal_link("t.me/addstickers/12345678901", sticker_set()); parse_internal_link("t.me/addstickers/12345678901", sticker_set("12345678901"));
parse_internal_link("t.me/addstickers/123456", sticker_set()); parse_internal_link("t.me/addstickers/123456", sticker_set("123456"));
parse_internal_link("t.me/addstickers/123456/123123/12/31/a/s//21w/?asdas#test", sticker_set()); parse_internal_link("t.me/addstickers/123456/123123/12/31/a/s//21w/?asdas#test", sticker_set("123456"));
parse_internal_link("tg:addstickers?set=abcdef", sticker_set()); parse_internal_link("tg:addstickers?set=abcdef", sticker_set("abcdef"));
parse_internal_link("tg:addstickers?set=abc%30ef", sticker_set("abc0ef"));
parse_internal_link("tg://addstickers?set=", unknown_deep_link()); parse_internal_link("tg://addstickers?set=", unknown_deep_link());
parse_internal_link("t.me/confirmphone?hash=abc%30ef&phone=", nullptr);
parse_internal_link("t.me/confirmphone/123456/123123/12/31/a/s//21w/?hash=abc%30ef&phone=123456789",
phone_number_confirmation("abc0ef", "123456789"));
parse_internal_link("t.me/confirmphone?hash=abc%30ef&phone=123456789",
phone_number_confirmation("abc0ef", "123456789"));
parse_internal_link("tg:confirmphone?hash=abc%30ef&phone=", unknown_deep_link());
parse_internal_link("tg:confirmphone?hash=abc%30ef&phone=123456789",
phone_number_confirmation("abc0ef", "123456789"));
parse_internal_link("tg://confirmphone?hash=123&phone=123456789123456789",
phone_number_confirmation("123", "123456789123456789"));
parse_internal_link("tg://confirmphone?hash=&phone=123456789123456789", unknown_deep_link());
parse_internal_link("tg://confirmphone?hash=123456789123456789&phone=", unknown_deep_link());
} }