Support shorter story links.
This commit is contained in:
parent
f39b906b28
commit
10c44c0cbf
@ -1578,12 +1578,16 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
|
|||||||
<< "&post=" << post << copy_arg("single") << thread
|
<< "&post=" << post << copy_arg("single") << thread
|
||||||
<< copy_arg("comment") << copy_arg("t"));
|
<< copy_arg("comment") << copy_arg("t"));
|
||||||
}
|
}
|
||||||
|
auto username = path[0];
|
||||||
|
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])));
|
||||||
|
}
|
||||||
if (path.size() == 2 && is_valid_web_app_name(path[1])) {
|
if (path.size() == 2 && is_valid_web_app_name(path[1])) {
|
||||||
// /<username>/<web_app_name>
|
// /<username>/<web_app_name>
|
||||||
// /<username>/<web_app_name>?startapp=<start_parameter>
|
// /<username>/<web_app_name>?startapp=<start_parameter>
|
||||||
return td::make_unique<InternalLinkWebApp>(path[0], path[1], url_query.get_arg("startapp").str());
|
return td::make_unique<InternalLinkWebApp>(std::move(username), path[1], url_query.get_arg("startapp").str());
|
||||||
}
|
}
|
||||||
auto username = path[0];
|
|
||||||
for (auto &arg : url_query.args_) {
|
for (auto &arg : url_query.args_) {
|
||||||
if (arg.first == "voicechat" || arg.first == "videochat" || arg.first == "livestream") {
|
if (arg.first == "voicechat" || arg.first == "videochat" || arg.first == "livestream") {
|
||||||
// /<username>?videochat
|
// /<username>?videochat
|
||||||
@ -1616,10 +1620,6 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
|
|||||||
// /<bot_username>?game=<short_name>
|
// /<bot_username>?game=<short_name>
|
||||||
return td::make_unique<InternalLinkGame>(std::move(username), arg.second);
|
return td::make_unique<InternalLinkGame>(std::move(username), arg.second);
|
||||||
}
|
}
|
||||||
if (arg.first == "story" && is_valid_story_id(arg.second)) {
|
|
||||||
// /<username>?story=<story_id>
|
|
||||||
return td::make_unique<InternalLinkStory>(std::move(username), StoryId(to_integer<int32>(arg.second)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!url_query.get_arg("attach").empty()) {
|
if (!url_query.get_arg("attach").empty()) {
|
||||||
// /<username>?attach=<bot_username>
|
// /<username>?attach=<bot_username>
|
||||||
@ -2106,7 +2106,7 @@ Result<string> LinkManager::get_internal_link_impl(const td_api::InternalLinkTyp
|
|||||||
if (is_internal) {
|
if (is_internal) {
|
||||||
return PSTRING() << "tg://resolve?domain=" << link->sender_username_ << "&story=" << link->story_id_;
|
return PSTRING() << "tg://resolve?domain=" << link->sender_username_ << "&story=" << link->story_id_;
|
||||||
} else {
|
} else {
|
||||||
return PSTRING() << get_t_me_url() << link->sender_username_ << "?story=" << link->story_id_;
|
return PSTRING() << get_t_me_url() << link->sender_username_ << "/s/" << link->story_id_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case td_api::internalLinkTypeTheme::ID: {
|
case td_api::internalLinkTypeTheme::ID: {
|
||||||
|
@ -1065,15 +1065,15 @@ TEST(Link, parse_internal_link_part4) {
|
|||||||
parse_internal_link("tg:resolve?domain=telegram&&&&&&&story=%31%39", story("telegram", 19));
|
parse_internal_link("tg:resolve?domain=telegram&&&&&&&story=%31%39", story("telegram", 19));
|
||||||
parse_internal_link("tg:resolve?domain=telegram&&&&&&&story=2222222222", public_chat("telegram"));
|
parse_internal_link("tg:resolve?domain=telegram&&&&&&&story=2222222222", public_chat("telegram"));
|
||||||
|
|
||||||
parse_internal_link("t.me/username/0/a//s/as?story=1234", story("username", 1234));
|
parse_internal_link("t.me/username/s/1234", story("username", 1234));
|
||||||
parse_internal_link("t.me/username/aasdas/2?test=1&story=3#12312", story("username", 3));
|
parse_internal_link("t.me/username/s/3?qwe=12312#12312", story("username", 3));
|
||||||
parse_internal_link("t.me/username/0?story=1", story("username", 1));
|
parse_internal_link("t.me/username/s/1", story("username", 1));
|
||||||
parse_internal_link("t.me/username/-1?story=2", story("username", 2));
|
parse_internal_link("t.me/username/s/2", story("username", 2));
|
||||||
parse_internal_link("t.me/username?story=5", story("username", 5));
|
parse_internal_link("t.me/username/s/5", story("username", 5));
|
||||||
parse_internal_link("t.me/username?story=", public_chat("username"));
|
parse_internal_link("t.me/username/s/", public_chat("username"));
|
||||||
parse_internal_link("t.me/username#story=123", public_chat("username"));
|
parse_internal_link("t.me/username#/s/123", public_chat("username"));
|
||||||
parse_internal_link("t.me//username?story=123", nullptr);
|
parse_internal_link("t.me/username?story=123", public_chat("username"));
|
||||||
parse_internal_link("https://telegram.dog/tele%63ram?story=%31%39", story("telecram", 19));
|
parse_internal_link("https://telegram.dog/tele%63ram/s/%31%39", story("telecram", 19));
|
||||||
|
|
||||||
parse_internal_link("tg:resolve?domain=username&appname=aasdasd&startapp=123asd",
|
parse_internal_link("tg:resolve?domain=username&appname=aasdasd&startapp=123asd",
|
||||||
web_app("username", "aasdasd", "123asd"));
|
web_app("username", "aasdasd", "123asd"));
|
||||||
|
Loading…
Reference in New Issue
Block a user