mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Allow opening external pages from attach bots.
This commit is contained in:
@@ -62,6 +62,7 @@ bool JoinGroupByHash(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Api::CheckChatInvite(controller, match->captured(1));
|
Api::CheckChatInvite(controller, match->captured(1));
|
||||||
|
controller->window().activate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,6 +77,7 @@ bool ShowStickerSet(
|
|||||||
controller->show(Box<StickerSetBox>(
|
controller->show(Box<StickerSetBox>(
|
||||||
controller,
|
controller,
|
||||||
StickerSetIdentifier{ .shortName = match->captured(1) }));
|
StickerSetIdentifier{ .shortName = match->captured(1) }));
|
||||||
|
controller->window().activate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +94,7 @@ bool ShowTheme(
|
|||||||
&controller->window(),
|
&controller->window(),
|
||||||
match->captured(1),
|
match->captured(1),
|
||||||
fromMessageId);
|
fromMessageId);
|
||||||
|
controller->window().activate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,6 +113,9 @@ bool SetLanguage(
|
|||||||
const auto languageId = match->captured(2);
|
const auto languageId = match->captured(2);
|
||||||
Lang::CurrentCloudManager().switchWithWarning(languageId);
|
Lang::CurrentCloudManager().switchWithWarning(languageId);
|
||||||
}
|
}
|
||||||
|
if (controller) {
|
||||||
|
controller->window().activate();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,6 +134,7 @@ bool ShareUrl(
|
|||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
controller->content()->shareUrlLayer(url, params.value("text"));
|
controller->content()->shareUrlLayer(url, params.value("text"));
|
||||||
|
controller->window().activate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -152,6 +159,7 @@ bool ConfirmPhone(
|
|||||||
controller,
|
controller,
|
||||||
phone,
|
phone,
|
||||||
hash);
|
hash);
|
||||||
|
controller->window().activate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,6 +174,7 @@ bool ShareGameScore(
|
|||||||
match->captured(1),
|
match->captured(1),
|
||||||
qthelp::UrlParamNameTransform::ToLower);
|
qthelp::UrlParamNameTransform::ToLower);
|
||||||
ShareGameScoreByHash(controller, params.value(qsl("hash")));
|
ShareGameScoreByHash(controller, params.value(qsl("hash")));
|
||||||
|
controller->window().activate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,6 +188,9 @@ bool ApplySocksProxy(
|
|||||||
ProxiesBoxController::ShowApplyConfirmation(
|
ProxiesBoxController::ShowApplyConfirmation(
|
||||||
MTP::ProxyData::Type::Socks5,
|
MTP::ProxyData::Type::Socks5,
|
||||||
params);
|
params);
|
||||||
|
if (controller) {
|
||||||
|
controller->window().activate();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,6 +204,9 @@ bool ApplyMtprotoProxy(
|
|||||||
ProxiesBoxController::ShowApplyConfirmation(
|
ProxiesBoxController::ShowApplyConfirmation(
|
||||||
MTP::ProxyData::Type::Mtproto,
|
MTP::ProxyData::Type::Mtproto,
|
||||||
params);
|
params);
|
||||||
|
if (controller) {
|
||||||
|
controller->window().activate();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,7 +258,7 @@ bool ShowWallPaper(
|
|||||||
const auto bg = params.value("bg_color");
|
const auto bg = params.value("bg_color");
|
||||||
const auto color = params.value("color");
|
const auto color = params.value("color");
|
||||||
const auto gradient = params.value("gradient");
|
const auto gradient = params.value("gradient");
|
||||||
return BackgroundPreviewBox::Start(
|
const auto result = BackgroundPreviewBox::Start(
|
||||||
controller,
|
controller,
|
||||||
(!color.isEmpty()
|
(!color.isEmpty()
|
||||||
? color
|
? color
|
||||||
@@ -251,6 +266,8 @@ bool ShowWallPaper(
|
|||||||
? gradient
|
? gradient
|
||||||
: params.value(qsl("slug"))),
|
: params.value(qsl("slug"))),
|
||||||
params);
|
params);
|
||||||
|
controller->window().activate();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] ChatAdminRights ParseRequestedAdminRights(
|
[[nodiscard]] ChatAdminRights ParseRequestedAdminRights(
|
||||||
@@ -376,6 +393,7 @@ bool ResolveUsernameOrPhone(
|
|||||||
: std::nullopt),
|
: std::nullopt),
|
||||||
.clickFromMessageId = fromMessageId,
|
.clickFromMessageId = fromMessageId,
|
||||||
});
|
});
|
||||||
|
controller->window().activate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,6 +433,7 @@ bool ResolvePrivatePost(
|
|||||||
: Navigation::RepliesByLinkInfo{ v::null },
|
: Navigation::RepliesByLinkInfo{ v::null },
|
||||||
.clickFromMessageId = fromMessageId,
|
.clickFromMessageId = fromMessageId,
|
||||||
});
|
});
|
||||||
|
controller->window().activate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -442,6 +461,7 @@ bool ResolveSettings(
|
|||||||
? ::Settings::Sessions::Id()
|
? ::Settings::Sessions::Id()
|
||||||
: ::Settings::Main::Id();
|
: ::Settings::Main::Id();
|
||||||
controller->showSettings(type);
|
controller->showSettings(type);
|
||||||
|
controller->window().activate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -27,6 +27,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
#include "window/window_controller.h"
|
#include "window/window_controller.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
|
#include "core/local_url_handlers.h"
|
||||||
|
#include "ui/basic_click_handlers.h"
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
#include "history/history_item.h"
|
#include "history/history_item.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
@@ -566,8 +568,7 @@ void AttachWebView::show(
|
|||||||
cancel();
|
cancel();
|
||||||
});
|
});
|
||||||
const auto sendData = crl::guard(this, [=](QByteArray data) {
|
const auto sendData = crl::guard(this, [=](QByteArray data) {
|
||||||
if (_peer != _bot) {
|
if (_peer != _bot || queryId) {
|
||||||
cancel();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto randomId = base::RandomValue<uint64>();
|
const auto randomId = base::RandomValue<uint64>();
|
||||||
@@ -581,6 +582,17 @@ void AttachWebView::show(
|
|||||||
}).send();
|
}).send();
|
||||||
cancel();
|
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(
|
auto title = Info::Profile::NameValue(
|
||||||
_bot
|
_bot
|
||||||
) | rpl::map([](const TextWithEntities &value) {
|
) | rpl::map([](const TextWithEntities &value) {
|
||||||
@@ -592,6 +604,7 @@ void AttachWebView::show(
|
|||||||
.userDataPath = _session->domain().local().webviewDataPath(),
|
.userDataPath = _session->domain().local().webviewDataPath(),
|
||||||
.title = std::move(title),
|
.title = std::move(title),
|
||||||
.bottom = rpl::single('@' + _bot->username),
|
.bottom = rpl::single('@' + _bot->username),
|
||||||
|
.handleLocalUri = handleLocalUri,
|
||||||
.sendData = sendData,
|
.sendData = sendData,
|
||||||
.close = close,
|
.close = close,
|
||||||
.themeParams = [] { return Window::Theme::WebViewParams(); },
|
.themeParams = [] { return Window::Theme::WebViewParams(); },
|
||||||
|
@@ -541,9 +541,11 @@ bool Panel::createWebview() {
|
|||||||
_delegate->panelWebviewMessage(message, save);
|
_delegate->panelWebviewMessage(message, save);
|
||||||
});
|
});
|
||||||
|
|
||||||
raw->setNavigationStartHandler([=](const QString &uri) {
|
raw->setNavigationStartHandler([=](const QString &uri, bool newWindow) {
|
||||||
if (!_delegate->panelWebviewNavigationAttempt(uri)) {
|
if (!_delegate->panelWebviewNavigationAttempt(uri)) {
|
||||||
return false;
|
return false;
|
||||||
|
} else if (newWindow) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
showWebviewProgress();
|
showWebviewProgress();
|
||||||
return true;
|
return true;
|
||||||
|
@@ -300,10 +300,12 @@ Panel::Progress::Progress(QWidget *parent, Fn<QRect()> rect)
|
|||||||
Panel::Panel(
|
Panel::Panel(
|
||||||
const QString &userDataPath,
|
const QString &userDataPath,
|
||||||
rpl::producer<QString> title,
|
rpl::producer<QString> title,
|
||||||
|
Fn<bool(QString)> handleLocalUri,
|
||||||
Fn<void(QByteArray)> sendData,
|
Fn<void(QByteArray)> sendData,
|
||||||
Fn<void()> close,
|
Fn<void()> close,
|
||||||
Fn<QByteArray()> themeParams)
|
Fn<QByteArray()> themeParams)
|
||||||
: _userDataPath(userDataPath)
|
: _userDataPath(userDataPath)
|
||||||
|
, _handleLocalUri(std::move(handleLocalUri))
|
||||||
, _sendData(std::move(sendData))
|
, _sendData(std::move(sendData))
|
||||||
, _close(std::move(close))
|
, _close(std::move(close))
|
||||||
, _widget(std::make_unique<SeparatePanel>()) {
|
, _widget(std::make_unique<SeparatePanel>()) {
|
||||||
@@ -553,12 +555,15 @@ bool Panel::createWebview() {
|
|||||||
sendDataMessage(list.at(1));
|
sendDataMessage(list.at(1));
|
||||||
} else if (command == "web_app_setup_main_button") {
|
} else if (command == "web_app_setup_main_button") {
|
||||||
processMainButtonMessage(list.at(1));
|
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();
|
showWebviewProgress();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@@ -794,6 +799,7 @@ std::unique_ptr<Panel> Show(Args &&args) {
|
|||||||
auto result = std::make_unique<Panel>(
|
auto result = std::make_unique<Panel>(
|
||||||
args.userDataPath,
|
args.userDataPath,
|
||||||
std::move(args.title),
|
std::move(args.title),
|
||||||
|
std::move(args.handleLocalUri),
|
||||||
std::move(args.sendData),
|
std::move(args.sendData),
|
||||||
std::move(args.close),
|
std::move(args.close),
|
||||||
std::move(args.themeParams));
|
std::move(args.themeParams));
|
||||||
|
@@ -32,6 +32,7 @@ public:
|
|||||||
Panel(
|
Panel(
|
||||||
const QString &userDataPath,
|
const QString &userDataPath,
|
||||||
rpl::producer<QString> title,
|
rpl::producer<QString> title,
|
||||||
|
Fn<bool(QString)> handleLocalUri,
|
||||||
Fn<void(QByteArray)> sendData,
|
Fn<void(QByteArray)> sendData,
|
||||||
Fn<void()> close,
|
Fn<void()> close,
|
||||||
Fn<QByteArray()> themeParams);
|
Fn<QByteArray()> themeParams);
|
||||||
@@ -75,6 +76,7 @@ private:
|
|||||||
void setupProgressGeometry();
|
void setupProgressGeometry();
|
||||||
|
|
||||||
QString _userDataPath;
|
QString _userDataPath;
|
||||||
|
Fn<bool(QString)> _handleLocalUri;
|
||||||
Fn<void(QByteArray)> _sendData;
|
Fn<void(QByteArray)> _sendData;
|
||||||
Fn<void()> _close;
|
Fn<void()> _close;
|
||||||
std::unique_ptr<SeparatePanel> _widget;
|
std::unique_ptr<SeparatePanel> _widget;
|
||||||
@@ -95,6 +97,7 @@ struct Args {
|
|||||||
QString userDataPath;
|
QString userDataPath;
|
||||||
rpl::producer<QString> title;
|
rpl::producer<QString> title;
|
||||||
rpl::producer<QString> bottom;
|
rpl::producer<QString> bottom;
|
||||||
|
Fn<bool(QString)> handleLocalUri;
|
||||||
Fn<void(QByteArray)> sendData;
|
Fn<void(QByteArray)> sendData;
|
||||||
Fn<void()> close;
|
Fn<void()> close;
|
||||||
Fn<QByteArray()> themeParams;
|
Fn<QByteArray()> themeParams;
|
||||||
|
Submodule Telegram/lib_webview updated: d08b8cc840...cf52486beb
Reference in New Issue
Block a user