mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 07:07:08 +02:00
Support web_app_request_phone attach bot requests.
This commit is contained in:
parent
2524b9a4c6
commit
4ca6af33d4
6 changed files with 52 additions and 1 deletions
Telegram
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -80,6 +80,9 @@ public:
|
|||
QString phrasePanelCloseWarning() override;
|
||||
QString phrasePanelCloseUnsaved() override;
|
||||
QString phrasePanelCloseAnyway() override;
|
||||
QString phraseBotSharePhone() override;
|
||||
QString phraseBotSharePhoneTitle() override;
|
||||
QString phraseBotSharePhoneConfirm() override;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -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(); },
|
||||
|
|
|
@ -340,6 +340,7 @@ Panel::Panel(
|
|||
Fn<void(QString)> handleInvoice,
|
||||
Fn<void(QByteArray)> sendData,
|
||||
Fn<void()> close,
|
||||
QString phone,
|
||||
MenuButtons menuButtons,
|
||||
Fn<void(MenuButton)> handleMenuButton,
|
||||
Fn<Webview::ThemeParams()> 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<SeparatePanel>()) {
|
||||
|
@ -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<Panel> 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));
|
||||
|
|
|
@ -49,6 +49,7 @@ public:
|
|||
Fn<void(QString)> handleInvoice,
|
||||
Fn<void(QByteArray)> sendData,
|
||||
Fn<void()> close,
|
||||
QString phone,
|
||||
MenuButtons menuButtons,
|
||||
Fn<void(MenuButton)> handleMenuButton,
|
||||
Fn<Webview::ThemeParams()> 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<void(QString)> _handleInvoice;
|
||||
Fn<void(QByteArray)> _sendData;
|
||||
Fn<void()> _close;
|
||||
QString _phone;
|
||||
bool _closeNeedConfirmation = false;
|
||||
MenuButtons _menuButtons = {};
|
||||
Fn<void(MenuButton)> _handleMenuButton;
|
||||
|
@ -137,6 +140,7 @@ struct Args {
|
|||
Fn<void(QString)> handleInvoice;
|
||||
Fn<void(QByteArray)> sendData;
|
||||
Fn<void()> close;
|
||||
QString phone;
|
||||
MenuButtons menuButtons;
|
||||
Fn<void(MenuButton)> handleMenuButton;
|
||||
Fn<Webview::ThemeParams()> themeParams;
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit e65d4965257d5ab4b6bcff99b51ee50f0b690843
|
||||
Subproject commit 1d34c64da8bc234c4d5dd8ebaff7f249d897c7d7
|
Loading…
Add table
Reference in a new issue