diff --git a/Telegram/SourceFiles/core/click_handler_types.h b/Telegram/SourceFiles/core/click_handler_types.h index de57083220..15a7dc1f95 100644 --- a/Telegram/SourceFiles/core/click_handler_types.h +++ b/Telegram/SourceFiles/core/click_handler_types.h @@ -38,6 +38,7 @@ class SessionController; class PeerData; struct ClickHandlerContext { FullMsgId itemId; + QString attachBotWebviewUrl; // Is filled from sections. Fn elementDelegate; base::weak_ptr sessionWindow; diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index 61d31e64d7..9daf74d620 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -447,6 +447,7 @@ bool ResolveUsernameOrPhone( ? std::make_optional(params.value(u"voicechat"_q)) : std::nullopt), .clickFromMessageId = myContext.itemId, + .clickFromAttachBotWebviewUrl = myContext.attachBotWebviewUrl, }); return true; } @@ -473,7 +474,7 @@ bool ResolvePrivatePost( if (!channelId || (msgId && !IsServerMsgId(msgId))) { return false; } - const auto fromMessageId = context.value().itemId; + const auto my = context.value(); using Navigation = Window::SessionNavigation; controller->showPeerByLink(Navigation::PeerByLinkInfo{ .usernameOrId = channelId, @@ -487,7 +488,8 @@ bool ResolvePrivatePost( Navigation::ThreadId{ threadId } } : Navigation::RepliesByLinkInfo{ v::null }, - .clickFromMessageId = fromMessageId, + .clickFromMessageId = my.itemId, + .clickFromAttachBotWebviewUrl = my.attachBotWebviewUrl, }); controller->window().activate(); return true; diff --git a/Telegram/SourceFiles/data/data_stories.cpp b/Telegram/SourceFiles/data/data_stories.cpp index 642265b6d8..661c287770 100644 --- a/Telegram/SourceFiles/data/data_stories.cpp +++ b/Telegram/SourceFiles/data/data_stories.cpp @@ -345,7 +345,8 @@ void Stories::parseAndApply(const MTPUserStories &stories) { } sort(list); }; - if (result.user->isBot() + if (result.user->isSelf() + || result.user->isBot() || result.user->isServiceUser() || result.user->isContact()) { const auto hidden = result.user->hasStoriesHidden(); diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp index e00e50d430..be7a814728 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "inline_bots/bot_attach_web_view.h" #include "api/api_common.h" +#include "core/click_handler_types.h" #include "data/data_bot_app.h" #include "data/data_user.h" #include "data/data_file_origin.h" @@ -568,7 +569,7 @@ void AttachWebView::cancel() { _session->api().request(base::take(_requestId)).cancel(); _session->api().request(base::take(_prolongId)).cancel(); _panel = nullptr; - _context = nullptr; + _lastShownContext = base::take(_context); _bot = nullptr; _app = nullptr; _botUsername = QString(); @@ -713,6 +714,14 @@ void AttachWebView::removeFromMenu(not_null bot) { }); } +std::optional AttachWebView::lookupLastAction( + const QString &url) const { + if (_lastShownUrl == url && _lastShownContext) { + return _lastShownContext->action; + } + return std::nullopt; +} + void AttachWebView::resolve() { resolveUsername(_botUsername, [=](not_null bot) { if (!_context) { @@ -1049,7 +1058,7 @@ void AttachWebView::show( } crl::on_main(this, [=] { cancel(); }); }); - const auto handleLocalUri = [close](QString uri) { + const auto handleLocalUri = [close, url](QString uri) { const auto local = Core::TryConvertUrlToLocal(uri); if (uri == local || Core::InternalPassportLink(local)) { return local.startsWith(u"tg://"_q); @@ -1058,7 +1067,10 @@ void AttachWebView::show( } close(); crl::on_main([=] { - UrlClickHandler::Open(local, {}); + const auto variant = QVariant::fromValue(ClickHandlerContext{ + .attachBotWebviewUrl = url, + }); + UrlClickHandler::Open(local, variant); }); return true; }; @@ -1142,6 +1154,7 @@ void AttachWebView::show( } }); + _lastShownUrl = url; _panel = Ui::BotWebView::Show({ .url = url, .userDataPath = _session->domain().local().webviewDataPath(), diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.h b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.h index 658f59940b..0cbd71ab45 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.h +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.h @@ -122,6 +122,9 @@ public: PeerTypes chooseTypes); void removeFromMenu(not_null bot); + [[nodiscard]] std::optional lookupLastAction( + const QString &url) const; + static void ClearAll(); private: @@ -180,6 +183,8 @@ private: const not_null _session; std::unique_ptr _context; + std::unique_ptr _lastShownContext; + QString _lastShownUrl; UserData *_bot = nullptr; QString _botUsername; QString _botAppName; diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 657876a594..d37fd7bd0d 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -521,10 +521,13 @@ void SessionNavigation::showPeerByLinkResolved( const auto contextPeer = item ? item->history()->peer : bot; + const auto action = bot->session().attachWebView().lookupLastAction( + info.clickFromAttachBotWebviewUrl + ).value_or(Api::SendAction(bot->owner().history(contextPeer))); crl::on_main(this, [=] { bot->session().attachWebView().requestApp( parentController(), - Api::SendAction(bot->owner().history(contextPeer)), + action, bot, info.botAppName, info.startToken, diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index 509fa2818f..9536894ee7 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -217,6 +217,7 @@ public: InlineBots::PeerTypes attachBotChooseTypes; std::optional voicechatHash; FullMsgId clickFromMessageId; + QString clickFromAttachBotWebviewUrl; }; void showPeerByLink(const PeerByLinkInfo &info);