Support alternative boost links.

This commit is contained in:
levlam 2023-09-26 13:08:54 +03:00
parent 84f2985154
commit ce5c3f32e7
2 changed files with 20 additions and 0 deletions

View File

@ -1643,6 +1643,18 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
<< copy_arg("comment") << copy_arg("t"));
}
auto username = path[0];
if (to_lower(username) == "boost") {
if (path.size() == 2 && is_valid_username(path[1])) {
// /boost/<username>
return td::make_unique<InternalLinkDialogBoost>(PSTRING() << "tg://boost?domain=" << url_encode(path[1]));
}
auto channel_id = url_query.get_arg("c");
if (path.size() == 1 && to_integer<int64>(channel_id) > 0) {
// /boost?c=<channel_id>
return td::make_unique<InternalLinkDialogBoost>(PSTRING()
<< "tg://boost?channel=" << to_integer<int64>(channel_id));
}
}
if (path.size() == 3 && path[1] == "s" && is_valid_story_id(path[2])) {
// /<username>/s/<story_id>
return td::make_unique<InternalLinkStory>(std::move(username), StoryId(to_integer<int32>(path[2])));

View File

@ -400,6 +400,14 @@ TEST(Link, parse_internal_link_part1) {
parse_internal_link("t.me/c/123456789012?boost", chat_boost("tg://boost?channel=123456789012"));
parse_internal_link("t.me/c/123456789012?boost=12312&domain=123", chat_boost("tg://boost?channel=123456789012"));
parse_internal_link("t.me/boost/s/12345", story("boost", 12345));
parse_internal_link("t.me/boost/s", chat_boost("tg://boost?domain=s"));
parse_internal_link("t.me/boost/12", message("tg://resolve?domain=boost&post=12"));
parse_internal_link("t.me/boost?cc=1#c=1", public_chat("boost"));
parse_internal_link("t.me/boost?c=-1", public_chat("boost"));
parse_internal_link("t.me/boost?c=12telegram", chat_boost("tg://boost?channel=12"));
parse_internal_link("t.me/bOoSt?c=12telegram", chat_boost("tg://boost?channel=12"));
parse_internal_link("tg:boost?domain=username/12345&single", chat_boost("tg://boost?domain=username%2F12345"));
parse_internal_link("tg:boost?domain=username&channel=12345", chat_boost("tg://boost?domain=username"));
parse_internal_link("tg:boost?channel=12345&domain=username", chat_boost("tg://boost?domain=username"));