From 80bec508b620e24290d3d5b756e7bafba86db898 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 21 Jun 2023 12:57:57 +0400 Subject: [PATCH] Support new stories link t.me/username/s/123. --- Telegram/SourceFiles/apiwrap.cpp | 2 +- Telegram/SourceFiles/core/local_url_handlers.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 44c7d507e..ea70c516b 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -779,7 +779,7 @@ QString ApiWrap::exportDirectStoryLink(not_null story) { const auto fallback = [&] { const auto base = user->username(); const auto story = QString::number(storyId.story); - const auto query = base + "?story=" + story; + const auto query = base + "/s" + story; return session().createInternalLinkFull(query); }; const auto i = _unlikelyStoryLinks.find(storyId); diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index 2d013e612..df0c92771 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -383,7 +383,8 @@ bool ResolveUsernameOrPhone( if (const auto postId = postParam.toInt()) { post = postId; } - const auto storyId = params.value(u"story"_q).toInt(); + const auto storyParam = params.value(u"story"_q); + const auto storyId = storyParam.toInt(); const auto appname = params.value(u"appname"_q); const auto appstart = params.value(u"startapp"_q); const auto commentParam = params.value(u"comment"_q); @@ -423,7 +424,7 @@ bool ResolveUsernameOrPhone( .startToken = startToken, .startAdminRights = adminRights, .startAutoSubmit = myContext.botStartAutoSubmit, - .botAppName = appname.isEmpty() ? postParam : appname, + .botAppName = (appname.isEmpty() ? postParam : appname), .botAppForceConfirmation = myContext.mayShowConfirmation, .attachBotUsername = params.value(u"attach"_q), .attachBotToggleCommand = (params.contains(u"startattach"_q) @@ -1029,6 +1030,7 @@ QString TryConvertUrlToLocal(QString url) { "/?$|" "/[a-zA-Z0-9\\.\\_]+/?(\\?|$)|" "/\\d+/?(\\?|$)|" + "/s/\\d+/?(\\?|$)|" "/\\d+/\\d+/?(\\?|$)" ")"_q, query, matchOptions)) { const auto params = query.mid(usernameMatch->captured(0).size()).toString(); @@ -1038,6 +1040,8 @@ QString TryConvertUrlToLocal(QString url) { added = u"&topic=%1&post=%2"_q.arg(threadPostMatch->captured(1)).arg(threadPostMatch->captured(2)); } else if (const auto postMatch = regex_match(u"^/(\\d+)(/?\\?|/?$)"_q, usernameMatch->captured(2))) { added = u"&post="_q + postMatch->captured(1); + } else if (const auto storyMatch = regex_match(u"^/s/(\\d+)(/?\\?|/?$)"_q, usernameMatch->captured(2))) { + added = u"&story="_q + storyMatch->captured(1); } else if (const auto appNameMatch = regex_match(u"^/([a-zA-Z0-9\\.\\_]+)(/?\\?|/?$)"_q, usernameMatch->captured(2))) { added = u"&appname="_q + appNameMatch->captured(1); }