From 10c44c0cbfeaeccdb4efc61e93944c010d375d6e Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 22 Jun 2023 20:42:48 +0300 Subject: [PATCH] Support shorter story links. --- td/telegram/LinkManager.cpp | 14 +++++++------- test/link.cpp | 18 +++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/td/telegram/LinkManager.cpp b/td/telegram/LinkManager.cpp index 5b115c148..cfd66498b 100644 --- a/td/telegram/LinkManager.cpp +++ b/td/telegram/LinkManager.cpp @@ -1578,12 +1578,16 @@ unique_ptr LinkManager::parse_t_me_link_query(Slice q << "&post=" << post << copy_arg("single") << thread << copy_arg("comment") << copy_arg("t")); } + auto username = path[0]; + if (path.size() == 3 && path[1] == "s" && is_valid_story_id(path[2])) { + // //s/ + return td::make_unique(std::move(username), StoryId(to_integer(path[2]))); + } if (path.size() == 2 && is_valid_web_app_name(path[1])) { // // // //?startapp= - return td::make_unique(path[0], path[1], url_query.get_arg("startapp").str()); + return td::make_unique(std::move(username), path[1], url_query.get_arg("startapp").str()); } - auto username = path[0]; for (auto &arg : url_query.args_) { if (arg.first == "voicechat" || arg.first == "videochat" || arg.first == "livestream") { // /?videochat @@ -1616,10 +1620,6 @@ unique_ptr LinkManager::parse_t_me_link_query(Slice q // /?game= return td::make_unique(std::move(username), arg.second); } - if (arg.first == "story" && is_valid_story_id(arg.second)) { - // /?story= - return td::make_unique(std::move(username), StoryId(to_integer(arg.second))); - } } if (!url_query.get_arg("attach").empty()) { // /?attach= @@ -2106,7 +2106,7 @@ Result LinkManager::get_internal_link_impl(const td_api::InternalLinkTyp if (is_internal) { return PSTRING() << "tg://resolve?domain=" << link->sender_username_ << "&story=" << link->story_id_; } 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: { diff --git a/test/link.cpp b/test/link.cpp index 4a4666117..5c851cff4 100644 --- a/test/link.cpp +++ b/test/link.cpp @@ -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=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/aasdas/2?test=1&story=3#12312", story("username", 3)); - parse_internal_link("t.me/username/0?story=1", story("username", 1)); - parse_internal_link("t.me/username/-1?story=2", story("username", 2)); - parse_internal_link("t.me/username?story=5", story("username", 5)); - parse_internal_link("t.me/username?story=", public_chat("username")); - parse_internal_link("t.me/username#story=123", public_chat("username")); - parse_internal_link("t.me//username?story=123", nullptr); - parse_internal_link("https://telegram.dog/tele%63ram?story=%31%39", story("telecram", 19)); + parse_internal_link("t.me/username/s/1234", story("username", 1234)); + parse_internal_link("t.me/username/s/3?qwe=12312#12312", story("username", 3)); + parse_internal_link("t.me/username/s/1", story("username", 1)); + parse_internal_link("t.me/username/s/2", story("username", 2)); + parse_internal_link("t.me/username/s/5", story("username", 5)); + parse_internal_link("t.me/username/s/", public_chat("username")); + parse_internal_link("t.me/username#/s/123", public_chat("username")); + parse_internal_link("t.me/username?story=123", public_chat("username")); + 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", web_app("username", "aasdasd", "123asd"));