Add td_api::internalLinkTypeAuthenticationCode.
This commit is contained in:
parent
3e0e9f5291
commit
38d71ca7e0
@ -3000,7 +3000,10 @@ chatReportReasonCustom = ChatReportReason;
|
||||
|
||||
//@class InternalLinkType @description Describes an internal t.me or tg: link, which must be processed by the app in a special way
|
||||
|
||||
//@description The link is a link to a background. Call searchBackground with a given background name to process the link @background_name Name of the background
|
||||
//@description The link contains an authentication code. Call checkAuthenticationCode with the code if the current authorization state is authorizationStateWaitCode @code The authentication code
|
||||
internalLinkTypeAuthenticationCode code:string = InternalLinkType;
|
||||
|
||||
//@description The link is a link to a background. Call searchBackground with the given background name to process the link @background_name Name of the background
|
||||
internalLinkTypeBackground background_name:string = InternalLinkType;
|
||||
|
||||
//@description The link is a link to a Telegram message. Call getMessageLinkInfo to process the link
|
||||
|
@ -23,6 +23,22 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
class LinkManager::InternalLinkAuthenticationCode : public InternalLink {
|
||||
string code_;
|
||||
|
||||
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
|
||||
return td_api::make_object<td_api::internalLinkTypeAuthenticationCode>(code_);
|
||||
}
|
||||
|
||||
InternalLinkType get_type() const final {
|
||||
return InternalLinkType::AuthenticationCode;
|
||||
}
|
||||
|
||||
public:
|
||||
explicit InternalLinkAuthenticationCode(string code) : code_(std::move(code)) {
|
||||
}
|
||||
};
|
||||
|
||||
class LinkManager::InternalLinkBackground : public InternalLink {
|
||||
string background_name_;
|
||||
|
||||
@ -303,7 +319,7 @@ LinkManager::LinkInfo LinkManager::get_link_info(Slice link) {
|
||||
}
|
||||
|
||||
vector<Slice> t_me_urls{Slice("t.me"), Slice("telegram.me"), Slice("telegram.dog")};
|
||||
if (Scheduler::context() != nullptr) {
|
||||
if (Scheduler::context() != nullptr) { // for tests only
|
||||
string cur_t_me_url = G()->shared_config().get_option_string("t_me_url");
|
||||
if (tolower_begins_with(cur_t_me_url, "http://") || tolower_begins_with(cur_t_me_url, "https://")) {
|
||||
Slice t_me_url = cur_t_me_url;
|
||||
@ -386,6 +402,11 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
|
||||
if (has_arg("domain") && has_arg("post")) {
|
||||
return td::make_unique<InternalLinkMessage>();
|
||||
}
|
||||
} else if (path.size() == 1 && path[0] == "login") {
|
||||
// login?code=123456
|
||||
if (has_arg("code")) {
|
||||
return td::make_unique<InternalLinkAuthenticationCode>(get_arg("code"));
|
||||
}
|
||||
} else if (path.size() == 1 && path[0] == "privatepost") {
|
||||
// privatepost?channel=123456789&msg_id=12345
|
||||
if (has_arg("channel") && has_arg("msg_id")) {
|
||||
@ -440,6 +461,11 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
|
||||
// /c/123456789/12345
|
||||
return td::make_unique<InternalLinkMessage>();
|
||||
}
|
||||
} else if (path[0] == "login") {
|
||||
if (path.size() >= 2 && !path[1].empty()) {
|
||||
// /login/<code>
|
||||
return td::make_unique<InternalLinkAuthenticationCode>(path[1]);
|
||||
}
|
||||
} else if (path[0] == "bg") {
|
||||
if (path.size() >= 2 && !path[1].empty()) {
|
||||
// /bg/<hex_color>
|
||||
|
@ -33,7 +33,7 @@ class LinkManager : public Actor {
|
||||
LinkManager &operator=(LinkManager &&) = delete;
|
||||
~LinkManager() override;
|
||||
|
||||
enum class InternalLinkType : int32 { Background, Message, MessageDraft, UnknownDeepLink };
|
||||
enum class InternalLinkType : int32 { AuthenticationCode, Background, Message, MessageDraft, UnknownDeepLink };
|
||||
|
||||
class InternalLink {
|
||||
public:
|
||||
@ -77,6 +77,7 @@ class LinkManager : public Actor {
|
||||
private:
|
||||
void tear_down() override;
|
||||
|
||||
class InternalLinkAuthenticationCode;
|
||||
class InternalLinkBackground;
|
||||
class InternalLinkMessage;
|
||||
class InternalLinkMessageDraft;
|
||||
|
@ -64,6 +64,9 @@ static void parse_internal_link(td::string url, td::td_api::object_ptr<td::td_ap
|
||||
}
|
||||
|
||||
TEST(Link, parse_internal_link) {
|
||||
auto authentication_code = [](td::string code) {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeAuthenticationCode>(code);
|
||||
};
|
||||
auto background = [](td::string background_name) {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeBackground>(background_name);
|
||||
};
|
||||
@ -219,4 +222,23 @@ TEST(Link, parse_internal_link) {
|
||||
parse_internal_link("https://t.me/msg?url=&text=@", message_draft(" @", false));
|
||||
parse_internal_link("https://t.me/msg?url=@&text=@", message_draft(" @\n@", true));
|
||||
parse_internal_link("https://t.me/msg?url=%FF&text=1", nullptr);
|
||||
|
||||
parse_internal_link("tg:login?codec=12345", unknown_deep_link());
|
||||
parse_internal_link("tg:login", unknown_deep_link());
|
||||
parse_internal_link("tg:login?code=abacaba", authentication_code("abacaba"));
|
||||
parse_internal_link("tg:login?code=123456", authentication_code("123456"));
|
||||
|
||||
parse_internal_link("t.me/login?codec=12345", nullptr);
|
||||
parse_internal_link("t.me/login", nullptr);
|
||||
parse_internal_link("t.me/login/", nullptr);
|
||||
parse_internal_link("t.me/login//12345", nullptr);
|
||||
parse_internal_link("t.me/login?/12345", nullptr);
|
||||
parse_internal_link("t.me/login/?12345", nullptr);
|
||||
parse_internal_link("t.me/login/#12345", nullptr);
|
||||
parse_internal_link("t.me/login/abacaba", authentication_code("abacaba"));
|
||||
parse_internal_link("t.me/login/aba%20aba", authentication_code("aba aba"));
|
||||
parse_internal_link("t.me/login/123456a", authentication_code("123456a"));
|
||||
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"));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user