From e59a60b3b50011b1f0b90f5b73d9f95dec0c5cc4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 6 Oct 2023 17:18:09 +0400 Subject: [PATCH] Handle new 'web_app_setup_settings_button' event. --- Telegram/SourceFiles/data/data_bot_app.h | 1 - .../SourceFiles/inline_bots/bot_attach_web_view.cpp | 10 +--------- Telegram/SourceFiles/inline_bots/bot_attach_web_view.h | 1 - .../SourceFiles/ui/chat/attach/attach_bot_webview.cpp | 8 +++++++- .../SourceFiles/ui/chat/attach/attach_bot_webview.h | 9 +++++---- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Telegram/SourceFiles/data/data_bot_app.h b/Telegram/SourceFiles/data/data_bot_app.h index 715fb03c0..7de4aefe8 100644 --- a/Telegram/SourceFiles/data/data_bot_app.h +++ b/Telegram/SourceFiles/data/data_bot_app.h @@ -24,5 +24,4 @@ struct BotAppData { uint64 accessHash = 0; uint64 hash = 0; - bool hasSettings = false; }; diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp index 8f77bbf4b..e99f48e1b 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp @@ -117,7 +117,6 @@ constexpr auto kRefreshBotsTimeout = 60 * 60 * crl::time(1000); .inMainMenu = data.is_show_in_side_menu(), .inAttachMenu = data.is_show_in_attach_menu(), .disclaimerRequired = data.is_side_menu_disclaimer_needed(), - .hasSettings = data.is_has_settings(), .requestWriteAccess = data.is_request_write_access(), } : std::optional(); }); @@ -1261,7 +1260,6 @@ void AttachWebView::requestApp( _bot->id, data.vapp()); _app = received ? received : already; - _app->hasSettings = data.is_has_settings(); if (!_app) { cancel(); showToast(tr::lng_username_app_not_found(tr::now)); @@ -1433,19 +1431,13 @@ void AttachWebView::show( _attachBots, not_null{ _bot }, &AttachWebViewBot::user); - const auto hasSettings = app - ? app->hasSettings - : ((attached != end(_attachBots)) - && !attached->inactive - && attached->hasSettings); const auto hasOpenBot = !_context || (_bot != _context->action.history->peer) || fromMainMenu; const auto hasRemoveFromMenu = !app && (attached != end(_attachBots)) && (!attached->inactive || attached->inMainMenu); - const auto buttons = (hasSettings ? Button::Settings : Button::None) - | (hasOpenBot ? Button::OpenBot : Button::None) + const auto buttons = (hasOpenBot ? Button::OpenBot : Button::None) | (!hasRemoveFromMenu ? Button::None : attached->inMainMenu diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.h b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.h index 04fbd06f4..67b1bead4 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.h +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.h @@ -66,7 +66,6 @@ struct AttachWebViewBot { bool inMainMenu : 1 = false; bool inAttachMenu : 1 = false; bool disclaimerRequired : 1 = false; - bool hasSettings : 1 = false; bool requestWriteAccess : 1 = false; }; diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp index 9b9f82215..6eff646ae 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp @@ -522,7 +522,7 @@ bool Panel::showWebview( _webviewBottom->resize(_webviewBottom->width(), height); } _widget->setMenuAllowed([=](const Ui::Menu::MenuCallback &callback) { - if (_menuButtons & MenuButton::Settings) { + if (_hasSettingsButton) { callback(tr::lng_bot_settings(tr::now), [=] { postEvent("settings_button_pressed"); }, &st::menuIconSettings); @@ -628,6 +628,8 @@ bool Panel::createWebview(const Webview::ThemeParams ¶ms) { processMainButtonMessage(arguments); } else if (command == "web_app_setup_back_button") { processBackButtonMessage(arguments); + } else if (command == "web_app_setup_settings_button") { + processSettingsButtonMessage(arguments); } else if (command == "web_app_request_theme") { _themeUpdateForced.fire({}); } else if (command == "web_app_request_viewport") { @@ -1104,6 +1106,10 @@ void Panel::processBackButtonMessage(const QJsonObject &args) { _widget->setBackAllowed(args["is_visible"].toBool()); } +void Panel::processSettingsButtonMessage(const QJsonObject &args) { + _hasSettingsButton = args["is_visible"].toBool(); +} + void Panel::processHeaderColor(const QJsonObject &args) { if (const auto color = ParseColor(args["color"].toString())) { _widget->overrideTitleColor(color); diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h index d8e2883db..28ea96cc2 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h +++ b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h @@ -37,10 +37,9 @@ struct MainButtonArgs { enum class MenuButton { None = 0x00, - Settings = 0x01, - OpenBot = 0x02, - RemoveFromMenu = 0x04, - RemoveFromMainMenu = 0x08, + OpenBot = 0x01, + RemoveFromMenu = 0x02, + RemoveFromMainMenu = 0x04, }; inline constexpr bool is_flag_type(MenuButton) { return true; } using MenuButtons = base::flags; @@ -114,6 +113,7 @@ private: void switchInlineQueryMessage(const QJsonObject &args); void processMainButtonMessage(const QJsonObject &args); void processBackButtonMessage(const QJsonObject &args); + void processSettingsButtonMessage(const QJsonObject &args); void processHeaderColor(const QJsonObject &args); void openTgLink(const QJsonObject &args); void openExternalLink(const QJsonObject &args); @@ -145,6 +145,7 @@ private: QString _userDataPath; const not_null _delegate; bool _closeNeedConfirmation = false; + bool _hasSettingsButton = false; MenuButtons _menuButtons = {}; std::unique_ptr _widget; std::unique_ptr _webview;