From 03b6e2df1737391881cbc19b7c69011babeee5fa Mon Sep 17 00:00:00 2001 From: John Preston Date: Sat, 23 Nov 2024 09:37:26 +0400 Subject: [PATCH] Don't confirm each bot-url webapp open. --- .../inline_bots/bot_attach_web_view.cpp | 28 +++++++++++++++---- .../inline_bots/bot_attach_web_view.h | 12 ++++++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp index 52fda97bf..c5bf5ce1c 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp @@ -946,7 +946,12 @@ void WebViewInstance::resolve() { requestSimple(); }); }, [&](WebViewSourceLinkApp data) { - resolveApp(data.appname, data.token, !_context.maySkipConfirmation); + resolveApp( + data.appname, + data.token, + (_context.maySkipConfirmation + ? ConfirmType::None + : ConfirmType::Always)); }, [&](WebViewSourceLinkBotProfile) { confirmOpen([=] { requestMain(); @@ -994,14 +999,14 @@ bool WebViewInstance::openAppFromBotMenuLink() { if (appname.isEmpty()) { return false; } - resolveApp(appname, params.value(u"startapp"_q), true); + resolveApp(appname, params.value(u"startapp"_q), ConfirmType::Once); return true; } void WebViewInstance::resolveApp( const QString &appname, const QString &startparam, - bool forceConfirmation) { + ConfirmType confirmType) { const auto already = _session->data().findBotApp(_bot->id, appname); _requestId = _session->api().request(MTPmessages_GetBotApp( MTP_inputBotAppShortName( @@ -1021,8 +1026,11 @@ void WebViewInstance::resolveApp( close(); return; } - const auto confirm = data.is_inactive() || forceConfirmation; + const auto confirm = data.is_inactive() + || (confirmType != ConfirmType::None); const auto writeAccess = result.data().is_request_write_access(); + const auto forceConfirmation = data.is_inactive() + || (confirmType == ConfirmType::Always); // Check if this app can be added to main menu. // On fail it'll still be opened. @@ -1035,7 +1043,7 @@ void WebViewInstance::resolveApp( } else if (confirm) { confirmAppOpen(writeAccess, [=](bool allowWrite) { requestApp(allowWrite); - }); + }, forceConfirmation); } else { requestApp(false); } @@ -1082,10 +1090,18 @@ void WebViewInstance::confirmOpen(Fn done) { void WebViewInstance::confirmAppOpen( bool writeAccess, - Fn done) { + Fn done, + bool forceConfirmation) { + if (!forceConfirmation + && (_bot->isVerified() + || _session->local().isBotTrustedOpenWebView(_bot->id))) { + done(writeAccess); + return; + } _parentShow->show(Box([=](not_null box) { const auto allowed = std::make_shared(); const auto callback = [=](Fn close) { + _session->local().markBotTrustedOpenWebView(_bot->id); done((*allowed) && (*allowed)->checked()); close(); }; diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.h b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.h index febf74dfa..f0cb146a7 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.h +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.h @@ -230,12 +230,20 @@ private: void requestWithMenuAdd(); void maybeChooseAndRequestButton(PeerTypes supported); + enum class ConfirmType : uchar { + Always, + Once, + None, + }; void resolveApp( const QString &appname, const QString &startparam, - bool forceConfirmation); + ConfirmType confirmType); void confirmOpen(Fn done); - void confirmAppOpen(bool writeAccess, Fn done); + void confirmAppOpen( + bool writeAccess, + Fn done, + bool forceConfirmation); struct ShowArgs { QString url;