Allow HiddenUrlClickHandler to work in a payment form.

This commit is contained in:
John Preston 2022-06-20 17:14:14 +04:00
parent 7027c0db0b
commit 66e9c5ef16
8 changed files with 45 additions and 11 deletions

View File

@ -123,16 +123,17 @@ void HiddenUrlClickHandler::Open(QString url, QVariant context) {
const auto use = controller
? &controller->window()
: Core::App().activeWindow();
if (use) {
use->show(
Ui::MakeConfirmBox({
.text = (tr::lng_open_this_link(tr::now)
+ qsl("\n\n")
+ displayUrl),
.confirmed = [=](Fn<void()> hide) { hide(); open(); },
.confirmText = tr::lng_open_link(),
}),
Ui::LayerOption::KeepOther);
auto box = Ui::MakeConfirmBox({
.text = (tr::lng_open_this_link(tr::now)
+ qsl("\n\n")
+ displayUrl),
.confirmed = [=](Fn<void()> hide) { hide(); open(); },
.confirmText = tr::lng_open_link(),
});
if (my.show) {
my.show->showBox(std::move(box));
} else if (use) {
use->show(std::move(box), Ui::LayerOption::KeepOther);
}
} else {
open();

View File

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once
#include "ui/basic_click_handlers.h"
#include "data/data_msg_id.h"
constexpr auto kPeerLinkPeerIdProperty = 0x01;
constexpr auto kPhotoLinkMediaProperty = 0x02;
@ -15,6 +16,10 @@ constexpr auto kDocumentLinkMediaProperty = 0x03;
constexpr auto kSendReactionEmojiProperty = 0x04;
constexpr auto kReactionsCountEmojiProperty = 0x05;
namespace Ui {
class Show;
} // namespace Ui
namespace Main {
class Session;
} // namespace Main
@ -35,6 +40,7 @@ struct ClickHandlerContext {
// Is filled from sections.
Fn<HistoryView::ElementDelegate*()> elementDelegate;
base::weak_ptr<Window::SessionController> sessionWindow;
std::shared_ptr<Ui::Show> show;
bool skipBotAutoLogin = false;
bool botStartAutoSubmit = false;
// Is filled from peer info.

View File

@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/local_url_handlers.h" // TryConvertUrlToLocal.
#include "core/file_utilities.h" // File::OpenUrl.
#include "core/core_cloud_password.h" // Core::CloudPasswordState
#include "core/click_handler_types.h"
#include "lang/lang_keys.h"
#include "apiwrap.h"
#include "api/api_cloud_password.h"
@ -808,6 +809,12 @@ void CheckoutProcess::panelShowBox(object_ptr<Ui::BoxContent> box) {
_panel->showBox(std::move(box));
}
QVariant CheckoutProcess::panelClickHandlerContext() {
return QVariant::fromValue(ClickHandlerContext{
.show = _panel->uiShow(),
});
}
void CheckoutProcess::performInitialSilentValidation() {
const auto &invoice = _form->invoice();
const auto &saved = _form->information();

View File

@ -147,6 +147,7 @@ private:
Ui::UncheckedCardDetails data,
bool saveInformation) override;
void panelShowBox(object_ptr<Ui::BoxContent> box) override;
QVariant panelClickHandlerContext();
QString panelWebviewDataPath() override;

View File

@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/text/format_values.h"
#include "ui/text/text_utilities.h"
#include "ui/effects/radial_animation.h"
#include "ui/click_handler.h"
#include "lang/lang_keys.h"
#include "webview/webview_embed.h"
#include "webview/webview_interface.h"
@ -679,6 +680,17 @@ void Panel::requestTermsAcceptance(
st::boxRowPadding.right(),
st::defaultBoxCheckbox.margin.bottom(),
});
row->setAllowTextLines(5);
row->setClickHandlerFilter([=](
const ClickHandlerPtr &link,
Qt::MouseButton button) {
ActivateClickHandler(_widget.get(), link, ClickContext{
.button = button,
.other = _delegate->panelClickHandlerContext(),
});
return false;
});
(*update) = [=] { row->update(); };
struct State {
@ -830,6 +842,10 @@ void Panel::showCriticalError(const TextWithEntities &text) {
}
}
std::shared_ptr<Show> Panel::uiShow() {
return _widget->uiShow();
}
void Panel::showWebviewError(
const QString &text,
const Webview::Available &information) {

View File

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/object_ptr.h"
namespace Ui {
class Show;
class RpWidget;
class SeparatePanel;
class BoxContent;
@ -85,6 +86,7 @@ public:
void showBox(object_ptr<Ui::BoxContent> box);
void showToast(const TextWithEntities &text);
void showCriticalError(const TextWithEntities &text);
[[nodiscard]] std::shared_ptr<Show> uiShow();
[[nodiscard]] rpl::lifetime &lifetime();

View File

@ -53,6 +53,7 @@ public:
Ui::UncheckedCardDetails data,
bool saveInformation) = 0;
virtual void panelShowBox(object_ptr<BoxContent> box) = 0;
virtual QVariant panelClickHandlerContext() = 0;
virtual QString panelWebviewDataPath() = 0;
};

@ -1 +1 @@
Subproject commit 6f856ce495872bb202be03c056fdbcd13ec162f3
Subproject commit b305df8cc5c853b564ec0fe0b8b121c2a4e10b19