Support forum message links in getInternalLinkType.

This commit is contained in:
levlam 2022-11-04 14:56:25 +03:00
parent 939d43129c
commit 54799d0024
2 changed files with 24 additions and 6 deletions

View File

@ -1241,10 +1241,17 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
if (path[0] == "c") { if (path[0] == "c") {
if (path.size() >= 3 && to_integer<int64>(path[1]) > 0 && to_integer<int64>(path[2]) > 0) { if (path.size() >= 3 && to_integer<int64>(path[1]) > 0 && to_integer<int64>(path[2]) > 0) {
// /c/123456789/12345?single&thread=<thread_id>&comment=<message_id>&t=<media_timestamp> // /c/123456789/12345?single&thread=<thread_id>&comment=<message_id>&t=<media_timestamp>
// /c/123456789/1234/12345?single&comment=<message_id>&t=<media_timestamp>
is_first_arg = false; is_first_arg = false;
return td::make_unique<InternalLinkMessage>( auto post = to_integer<int64>(path[2]);
PSTRING() << "tg:privatepost?channel=" << to_integer<int64>(path[1]) << "&post=" << to_integer<int64>(path[2]) auto thread = PSTRING() << copy_arg("thread");
<< copy_arg("single") << copy_arg("thread") << copy_arg("comment") << copy_arg("t")); if (path.size() >= 4 && to_integer<int64>(path[3]) > 0) {
thread = PSTRING() << "&thread=" << post;
post = to_integer<int64>(path[3]);
}
return td::make_unique<InternalLinkMessage>(PSTRING() << "tg:privatepost?channel=" << to_integer<int64>(path[1])
<< "&post=" << post << copy_arg("single") << thread
<< copy_arg("comment") << copy_arg("t"));
} }
} else if (path[0] == "login") { } else if (path[0] == "login") {
if (path.size() >= 2 && !path[1].empty()) { if (path.size() >= 2 && !path[1].empty()) {
@ -1354,10 +1361,17 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
} else if (is_valid_username(path[0])) { } else if (is_valid_username(path[0])) {
if (path.size() >= 2 && to_integer<int64>(path[1]) > 0) { if (path.size() >= 2 && to_integer<int64>(path[1]) > 0) {
// /<username>/12345?single&thread=<thread_id>&comment=<message_id>&t=<media_timestamp> // /<username>/12345?single&thread=<thread_id>&comment=<message_id>&t=<media_timestamp>
// /<username>/1234/12345?single&comment=<message_id>&t=<media_timestamp>
is_first_arg = false; is_first_arg = false;
return td::make_unique<InternalLinkMessage>( auto post = to_integer<int64>(path[1]);
PSTRING() << "tg:resolve?domain=" << url_encode(path[0]) << "&post=" << to_integer<int64>(path[1]) auto thread = PSTRING() << copy_arg("thread");
<< copy_arg("single") << copy_arg("thread") << copy_arg("comment") << copy_arg("t")); if (path.size() >= 3 && to_integer<int64>(path[2]) > 0) {
thread = PSTRING() << "&thread=" << post;
post = to_integer<int64>(path[2]);
}
return td::make_unique<InternalLinkMessage>(PSTRING() << "tg:resolve?domain=" << url_encode(path[0])
<< "&post=" << post << copy_arg("single") << thread
<< copy_arg("comment") << copy_arg("t"));
} }
auto username = path[0]; auto username = path[0];
for (auto &arg : url_query.args_) { for (auto &arg : url_query.args_) {

View File

@ -327,6 +327,8 @@ TEST(Link, parse_internal_link) {
message("tg:resolve?domain=username&post=12345&single")); message("tg:resolve?domain=username&post=12345&single"));
parse_internal_link("t.me/username/12345/asdasd//asd/asd/asd/?single", parse_internal_link("t.me/username/12345/asdasd//asd/asd/asd/?single",
message("tg:resolve?domain=username&post=12345&single")); message("tg:resolve?domain=username&post=12345&single"));
parse_internal_link("t.me/username/12345/67890/asdasd//asd/asd/asd/?single",
message("tg:resolve?domain=username&post=67890&single&thread=12345"));
parse_internal_link("t.me/username/1asdasdas/asdasd//asd/asd/asd/?single", parse_internal_link("t.me/username/1asdasdas/asdasd//asd/asd/asd/?single",
message("tg:resolve?domain=username&post=1&single")); message("tg:resolve?domain=username&post=1&single"));
parse_internal_link("t.me/username/asd", public_chat("username")); parse_internal_link("t.me/username/asd", public_chat("username"));
@ -371,6 +373,8 @@ TEST(Link, parse_internal_link) {
parse_internal_link("t.me/c/12345/123", message("tg:privatepost?channel=12345&post=123")); parse_internal_link("t.me/c/12345/123", message("tg:privatepost?channel=12345&post=123"));
parse_internal_link("t.me/c/12345/123?single", message("tg:privatepost?channel=12345&post=123&single")); parse_internal_link("t.me/c/12345/123?single", message("tg:privatepost?channel=12345&post=123&single"));
parse_internal_link("t.me/c/12345/123/asd/asd////?single", message("tg:privatepost?channel=12345&post=123&single")); parse_internal_link("t.me/c/12345/123/asd/asd////?single", message("tg:privatepost?channel=12345&post=123&single"));
parse_internal_link("t.me/c/12345/123/456/asd/asd////?single",
message("tg:privatepost?channel=12345&post=456&single&thread=123"));
parse_internal_link("t.me/c/%312345/%3123?comment=456&t=789&single&thread=123%20%31", parse_internal_link("t.me/c/%312345/%3123?comment=456&t=789&single&thread=123%20%31",
message("tg:privatepost?channel=12345&post=123&single&thread=123%201&comment=456&t=789")); message("tg:privatepost?channel=12345&post=123&single&thread=123%201&comment=456&t=789"));