Support t.me subdomains.

This commit is contained in:
levlam 2022-09-02 16:34:05 +03:00
parent 03af40bc08
commit e595730735
2 changed files with 43 additions and 6 deletions

View File

@ -885,6 +885,24 @@ LinkManager::LinkInfo LinkManager::get_link_info(Slice link) {
return result;
}
auto host = url_decode(http_url.host_, false);
to_lower_inplace(host);
if (ends_with(host, ".t.me") && host.size() >= 9 && host.find('.') == host.size() - 5) {
Slice subdomain(&host[0], host.size() - 5);
if (is_valid_username(subdomain) && subdomain != "addemoji" && subdomain != "addstickers" &&
subdomain != "addtheme" && subdomain != "auth" && subdomain != "confirmphone" && subdomain != "invoice" &&
subdomain != "joinchat" && subdomain != "login" && subdomain != "proxy" && subdomain != "setlanguage" &&
subdomain != "share" && subdomain != "socks") {
result.is_internal_ = true;
result.is_tg_ = false;
result.query_ = PSTRING() << '/' << subdomain << http_url.query_;
return result;
}
}
if (begins_with(host, "www.")) {
host = host.substr(4);
}
vector<Slice> t_me_urls{Slice("t.me"), Slice("telegram.me"), Slice("telegram.dog")};
if (Scheduler::context() != nullptr) { // for tests only
string cur_t_me_url = G()->get_option_string("t_me_url");
@ -897,12 +915,6 @@ LinkManager::LinkInfo LinkManager::get_link_info(Slice link) {
}
}
auto host = url_decode(http_url.host_, false);
to_lower_inplace(host);
if (begins_with(host, "www.")) {
host = host.substr(4);
}
for (auto t_me_url : t_me_urls) {
if (host == t_me_url) {
result.is_internal_ = true;

View File

@ -921,4 +921,29 @@ TEST(Link, parse_internal_link) {
parse_internal_link("tg://settings/filters", settings());
parse_internal_link("tg://settings/language", language_settings());
parse_internal_link("tg://settings/privacy", privacy_and_security_settings());
parse_internal_link("username.t.me////0/a//s/as?start=", bot_start("username", ""));
parse_internal_link("username.t.me?start=as", bot_start("username", "as"));
parse_internal_link("username.t.me", public_chat("username"));
parse_internal_link("aAAb.t.me/12345?single", message("tg:resolve?domain=aaab&post=12345&single"));
parse_internal_link("telegram.t.me/195", message("tg:resolve?domain=telegram&post=195"));
parse_internal_link("shares.t.me", public_chat("shares"));
parse_internal_link("c.t.me/12345?single", nullptr);
parse_internal_link("aaa.t.me/12345?single", nullptr);
parse_internal_link("aaa_.t.me/12345?single", nullptr);
parse_internal_link("0aaa.t.me/12345?single", nullptr);
parse_internal_link("_aaa.t.me/12345?single", nullptr);
parse_internal_link("addemoji.t.me", nullptr);
parse_internal_link("addstickers.t.me", nullptr);
parse_internal_link("addtheme.t.me", nullptr);
parse_internal_link("auth.t.me", nullptr);
parse_internal_link("confirmphone.t.me", nullptr);
parse_internal_link("invoice.t.me", nullptr);
parse_internal_link("joinchat.t.me", nullptr);
parse_internal_link("login.t.me", nullptr);
parse_internal_link("proxy.t.me", nullptr);
parse_internal_link("setlanguage.t.me", nullptr);
parse_internal_link("share.t.me", nullptr);
parse_internal_link("socks.t.me", nullptr);
}