Allow opening external pages from attach bots.

This commit is contained in:
John Preston 2022-04-05 21:14:59 +04:00
parent 622474e83b
commit 73c5988e7e
6 changed files with 52 additions and 8 deletions

View file

@ -62,6 +62,7 @@ bool JoinGroupByHash(
return false;
}
Api::CheckChatInvite(controller, match->captured(1));
controller->window().activate();
return true;
}
@ -76,6 +77,7 @@ bool ShowStickerSet(
controller->show(Box<StickerSetBox>(
controller,
StickerSetIdentifier{ .shortName = match->captured(1) }));
controller->window().activate();
return true;
}
@ -92,6 +94,7 @@ bool ShowTheme(
&controller->window(),
match->captured(1),
fromMessageId);
controller->window().activate();
return true;
}
@ -110,6 +113,9 @@ bool SetLanguage(
const auto languageId = match->captured(2);
Lang::CurrentCloudManager().switchWithWarning(languageId);
}
if (controller) {
controller->window().activate();
}
return true;
}
@ -128,6 +134,7 @@ bool ShareUrl(
return false;
} else {
controller->content()->shareUrlLayer(url, params.value("text"));
controller->window().activate();
return true;
}
return false;
@ -152,6 +159,7 @@ bool ConfirmPhone(
controller,
phone,
hash);
controller->window().activate();
return true;
}
@ -166,6 +174,7 @@ bool ShareGameScore(
match->captured(1),
qthelp::UrlParamNameTransform::ToLower);
ShareGameScoreByHash(controller, params.value(qsl("hash")));
controller->window().activate();
return true;
}
@ -179,6 +188,9 @@ bool ApplySocksProxy(
ProxiesBoxController::ShowApplyConfirmation(
MTP::ProxyData::Type::Socks5,
params);
if (controller) {
controller->window().activate();
}
return true;
}
@ -192,6 +204,9 @@ bool ApplyMtprotoProxy(
ProxiesBoxController::ShowApplyConfirmation(
MTP::ProxyData::Type::Mtproto,
params);
if (controller) {
controller->window().activate();
}
return true;
}
@ -243,7 +258,7 @@ bool ShowWallPaper(
const auto bg = params.value("bg_color");
const auto color = params.value("color");
const auto gradient = params.value("gradient");
return BackgroundPreviewBox::Start(
const auto result = BackgroundPreviewBox::Start(
controller,
(!color.isEmpty()
? color
@ -251,6 +266,8 @@ bool ShowWallPaper(
? gradient
: params.value(qsl("slug"))),
params);
controller->window().activate();
return result;
}
[[nodiscard]] ChatAdminRights ParseRequestedAdminRights(
@ -376,6 +393,7 @@ bool ResolveUsernameOrPhone(
: std::nullopt),
.clickFromMessageId = fromMessageId,
});
controller->window().activate();
return true;
}
@ -415,6 +433,7 @@ bool ResolvePrivatePost(
: Navigation::RepliesByLinkInfo{ v::null },
.clickFromMessageId = fromMessageId,
});
controller->window().activate();
return true;
}
@ -442,6 +461,7 @@ bool ResolveSettings(
? ::Settings::Sessions::Id()
: ::Settings::Main::Id();
controller->showSettings(type);
controller->window().activate();
return true;
}

View file

@ -27,6 +27,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/window_controller.h"
#include "window/window_session_controller.h"
#include "core/application.h"
#include "core/local_url_handlers.h"
#include "ui/basic_click_handlers.h"
#include "history/history.h"
#include "history/history_item.h"
#include "lang/lang_keys.h"
@ -566,8 +568,7 @@ void AttachWebView::show(
cancel();
});
const auto sendData = crl::guard(this, [=](QByteArray data) {
if (_peer != _bot) {
cancel();
if (_peer != _bot || queryId) {
return;
}
const auto randomId = base::RandomValue<uint64>();
@ -581,6 +582,17 @@ void AttachWebView::show(
}).send();
cancel();
});
const auto handleLocalUri = [close](QString uri) {
const auto local = Core::TryConvertUrlToLocal(uri);
if (uri == local || Core::InternalPassportLink(local)) {
return local.startsWith(qstr("tg://"));
} else if (!local.startsWith(qstr("tg://"), Qt::CaseInsensitive)) {
return false;
}
UrlClickHandler::Open(local, {});
crl::on_main(close);
return true;
};
auto title = Info::Profile::NameValue(
_bot
) | rpl::map([](const TextWithEntities &value) {
@ -592,6 +604,7 @@ void AttachWebView::show(
.userDataPath = _session->domain().local().webviewDataPath(),
.title = std::move(title),
.bottom = rpl::single('@' + _bot->username),
.handleLocalUri = handleLocalUri,
.sendData = sendData,
.close = close,
.themeParams = [] { return Window::Theme::WebViewParams(); },

View file

@ -541,9 +541,11 @@ bool Panel::createWebview() {
_delegate->panelWebviewMessage(message, save);
});
raw->setNavigationStartHandler([=](const QString &uri) {
raw->setNavigationStartHandler([=](const QString &uri, bool newWindow) {
if (!_delegate->panelWebviewNavigationAttempt(uri)) {
return false;
} else if (newWindow) {
return false;
}
showWebviewProgress();
return true;

View file

@ -300,10 +300,12 @@ Panel::Progress::Progress(QWidget *parent, Fn<QRect()> rect)
Panel::Panel(
const QString &userDataPath,
rpl::producer<QString> title,
Fn<bool(QString)> handleLocalUri,
Fn<void(QByteArray)> sendData,
Fn<void()> close,
Fn<QByteArray()> themeParams)
: _userDataPath(userDataPath)
, _handleLocalUri(std::move(handleLocalUri))
, _sendData(std::move(sendData))
, _close(std::move(close))
, _widget(std::make_unique<SeparatePanel>()) {
@ -553,12 +555,15 @@ bool Panel::createWebview() {
sendDataMessage(list.at(1));
} else if (command == "web_app_setup_main_button") {
processMainButtonMessage(list.at(1));
} else if (command == "web_app_request_viewport") {
}
});
raw->setNavigationStartHandler([=](const QString &uri) {
raw->setNavigationStartHandler([=](const QString &uri, bool newWindow) {
if (_handleLocalUri(uri)) {
return false;
} else if (newWindow) {
return true;
}
showWebviewProgress();
return true;
});
@ -794,6 +799,7 @@ std::unique_ptr<Panel> Show(Args &&args) {
auto result = std::make_unique<Panel>(
args.userDataPath,
std::move(args.title),
std::move(args.handleLocalUri),
std::move(args.sendData),
std::move(args.close),
std::move(args.themeParams));

View file

@ -32,6 +32,7 @@ public:
Panel(
const QString &userDataPath,
rpl::producer<QString> title,
Fn<bool(QString)> handleLocalUri,
Fn<void(QByteArray)> sendData,
Fn<void()> close,
Fn<QByteArray()> themeParams);
@ -75,6 +76,7 @@ private:
void setupProgressGeometry();
QString _userDataPath;
Fn<bool(QString)> _handleLocalUri;
Fn<void(QByteArray)> _sendData;
Fn<void()> _close;
std::unique_ptr<SeparatePanel> _widget;
@ -95,6 +97,7 @@ struct Args {
QString userDataPath;
rpl::producer<QString> title;
rpl::producer<QString> bottom;
Fn<bool(QString)> handleLocalUri;
Fn<void(QByteArray)> sendData;
Fn<void()> close;
Fn<QByteArray()> themeParams;

@ -1 +1 @@
Subproject commit d08b8cc84054938cd6d694136709fcad32d5e6ce
Subproject commit cf52486beb79d23d6ad6302eb7a0b03e71761e94