From a5ffd8b7cf7ecbe60f5e413a7698e189b6c302b9 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 24 Jul 2024 13:44:15 +0200 Subject: [PATCH] Request new main web app. --- .../inline_bots/bot_attach_web_view.cpp | 33 +++++++++++++++++-- .../inline_bots/bot_attach_web_view.h | 1 + 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp index e7d842c64..e0a609f7a 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp @@ -651,7 +651,9 @@ void WebViewInstance::resolve() { }, [&](WebViewSourceLinkApp data) { resolveApp(data.appname, data.token, !_context.maySkipConfirmation); }, [&](WebViewSourceLinkBotProfile) { - requestWithMenuAdd(); + confirmOpen([=] { + requestMain(); + }); }, [&](WebViewSourceLinkAttachMenu data) { requestWithMenuAdd(); }, [&](WebViewSourceMainMenu) { @@ -667,7 +669,9 @@ void WebViewInstance::resolve() { }, [&](WebViewSourceGame game) { showGame(); }, [&](WebViewSourceBotProfile) { - requestWithMenuAdd(); + confirmOpen([=] { + requestMain(); + }); }); } @@ -868,6 +872,31 @@ void WebViewInstance::requestSimple() { }).send(); } +void WebViewInstance::requestMain() { + using Flag = MTPmessages_RequestMainWebView::Flag; + _requestId = _session->api().request(MTPmessages_RequestMainWebView( + MTP_flags(Flag::f_theme_params + | (_button.startCommand.isEmpty() + ? Flag() + : Flag::f_start_param) + | (v::is(_source) + ? (v::get(_source).compact + ? Flag::f_compact + : Flag(0)) + : Flag(0))), + _context.action->history->peer->input, + _bot->inputUser, + MTP_string(_button.startCommand), + MTP_dataJSON(MTP_bytes(botThemeParams().json)), + MTP_string("tdesktop") + )).done([=](const MTPWebViewResult &result) { + show(qs(result.data().vurl())); + }).fail([=](const MTP::Error &error) { + _parentShow->showToast(error.type()); + close(); + }).send(); +} + void WebViewInstance::requestApp(bool allowWrite) { Expects(_app != nullptr); Expects(_context.action.has_value()); diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.h b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.h index 6e11c87cd..ecccdd042 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.h +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.h @@ -239,6 +239,7 @@ private: void requestButton(); void requestSimple(); + void requestMain(); void requestApp(bool allowWrite); void requestWithMainMenuDisclaimer(); void requestWithMenuAdd();