From 4ca6af33d4cb75cd44e0db217cf6cd3aff8f6a36 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 15 Jul 2022 15:09:55 +0300 Subject: [PATCH] Support web_app_request_phone attach bot requests. --- Telegram/SourceFiles/core/ui_integration.cpp | 12 +++++++ Telegram/SourceFiles/core/ui_integration.h | 3 ++ .../inline_bots/bot_attach_web_view.cpp | 1 + .../ui/chat/attach/attach_bot_webview.cpp | 31 +++++++++++++++++++ .../ui/chat/attach/attach_bot_webview.h | 4 +++ Telegram/lib_ui | 2 +- 6 files changed, 52 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/core/ui_integration.cpp b/Telegram/SourceFiles/core/ui_integration.cpp index 58fba0308..050275d05 100644 --- a/Telegram/SourceFiles/core/ui_integration.cpp +++ b/Telegram/SourceFiles/core/ui_integration.cpp @@ -353,6 +353,18 @@ QString UiIntegration::phrasePanelCloseAnyway() { return tr::lng_bot_close_warning_sure(tr::now); } +QString UiIntegration::phraseBotSharePhone() { + return tr::lng_bot_share_phone(tr::now); +} + +QString UiIntegration::phraseBotSharePhoneTitle() { + return tr::lng_settings_phone_label(tr::now); +} + +QString UiIntegration::phraseBotSharePhoneConfirm() { + return tr::lng_bot_share_phone_confirm(tr::now); +} + bool OpenGLLastCheckFailed() { return QFile::exists(OpenGLCheckFilePath()); } diff --git a/Telegram/SourceFiles/core/ui_integration.h b/Telegram/SourceFiles/core/ui_integration.h index 5f9664682..a91aa1a4b 100644 --- a/Telegram/SourceFiles/core/ui_integration.h +++ b/Telegram/SourceFiles/core/ui_integration.h @@ -80,6 +80,9 @@ public: QString phrasePanelCloseWarning() override; QString phrasePanelCloseUnsaved() override; QString phrasePanelCloseAnyway() override; + QString phraseBotSharePhone() override; + QString phraseBotSharePhoneTitle() override; + QString phraseBotSharePhoneConfirm() override; }; diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp index f98b67194..59ed33ee6 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp @@ -884,6 +884,7 @@ void AttachWebView::show( .handleInvoice = handleInvoice, .sendData = sendData, .close = close, + .phone = _session->user()->phone(), .menuButtons = buttons, .handleMenuButton = handleMenuButton, .themeParams = [] { return Window::Theme::WebViewParams(); }, diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp index 0823557df..9c00fd2cb 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp @@ -340,6 +340,7 @@ Panel::Panel( Fn handleInvoice, Fn sendData, Fn close, + QString phone, MenuButtons menuButtons, Fn handleMenuButton, Fn themeParams) @@ -348,6 +349,7 @@ Panel::Panel( , _handleInvoice(std::move(handleInvoice)) , _sendData(std::move(sendData)) , _close(std::move(close)) +, _phone(phone) , _menuButtons(menuButtons) , _handleMenuButton(std::move(handleMenuButton)) , _widget(std::make_unique()) { @@ -656,6 +658,8 @@ bool Panel::createWebview() { openInvoice(arguments); } else if (command == "web_app_open_popup") { openPopup(arguments); + } else if (command == "web_app_request_phone") { + requestPhone(); } else if (command == "web_app_setup_closing_behavior") { setupClosingBehaviour(arguments); } @@ -817,6 +821,32 @@ void Panel::openPopup(const QJsonObject &args) { } } +void Panel::requestPhone() { + using Button = Webview::PopupArgs::Button; + const auto widget = _webview->window.widget(); + const auto weak = base::make_weak(this); + const auto integration = &Ui::Integration::Instance(); + const auto result = Webview::ShowBlockingPopup({ + .parent = widget ? widget->window() : nullptr, + .title = integration->phraseBotSharePhoneTitle(), + .text = integration->phraseBotSharePhone(), + .buttons = { + { + .id = "share", + .text = integration->phraseBotSharePhoneConfirm(), + }, + {.id = "cancel", .type = Button::Type::Cancel }, + }, + }); + if (weak) { + postEvent( + "phone_requested", + (result.id == "share" + ? "\"phone_number\": \"" + _phone + "\"" + : QString())); + } +} + void Panel::scheduleCloseWithConfirmation() { if (!_closeWithConfirmationScheduled) { _closeWithConfirmationScheduled = true; @@ -1080,6 +1110,7 @@ std::unique_ptr Show(Args &&args) { std::move(args.handleInvoice), std::move(args.sendData), std::move(args.close), + args.phone, args.menuButtons, std::move(args.handleMenuButton), std::move(args.themeParams)); diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h index fb53154df..c9880da98 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h +++ b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h @@ -49,6 +49,7 @@ public: Fn handleInvoice, Fn sendData, Fn close, + QString phone, MenuButtons menuButtons, Fn handleMenuButton, Fn themeParams); @@ -92,6 +93,7 @@ private: void openExternalLink(const QJsonObject &args); void openInvoice(const QJsonObject &args); void openPopup(const QJsonObject &args); + void requestPhone(); void setupClosingBehaviour(const QJsonObject &args); void createMainButton(); void scheduleCloseWithConfirmation(); @@ -108,6 +110,7 @@ private: Fn _handleInvoice; Fn _sendData; Fn _close; + QString _phone; bool _closeNeedConfirmation = false; MenuButtons _menuButtons = {}; Fn _handleMenuButton; @@ -137,6 +140,7 @@ struct Args { Fn handleInvoice; Fn sendData; Fn close; + QString phone; MenuButtons menuButtons; Fn handleMenuButton; Fn themeParams; diff --git a/Telegram/lib_ui b/Telegram/lib_ui index e65d49652..1d34c64da 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit e65d4965257d5ab4b6bcff99b51ee50f0b690843 +Subproject commit 1d34c64da8bc234c4d5dd8ebaff7f249d897c7d7