mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-08-06 11:52:58 +00:00
Confirm telegra.ph external opening.
This commit is contained in:
@@ -87,6 +87,11 @@ constexpr auto kReminderSetToastDuration = 4 * crl::time(1000);
|
||||
return UrlRequiresConfirmation(url) || IsTelegramShortLinkHost(url);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool RequiresConfirmationAfterIvFallback(const QUrl &url) {
|
||||
const auto host = url.host().toLower();
|
||||
return (host == u"telegra.ph"_q) || (host == u"te.legra.ph"_q);
|
||||
}
|
||||
|
||||
// Possible context owners: media viewer, profile, history widget.
|
||||
|
||||
void SearchByHashtag(ClickContext context, const QString &tag) {
|
||||
@@ -253,9 +258,6 @@ void HiddenUrlClickHandler::Open(QString url, QVariant context) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto open = [=] {
|
||||
UrlClickHandler::Open(url, context);
|
||||
};
|
||||
if (url.startsWith(u"tg://"_q, Qt::CaseInsensitive)
|
||||
|| url.startsWith(u"internal:"_q, Qt::CaseInsensitive)) {
|
||||
UrlClickHandler::Open(url, QVariant::fromValue([&] {
|
||||
@@ -267,9 +269,31 @@ void HiddenUrlClickHandler::Open(QString url, QVariant context) {
|
||||
const auto parsedUrl = url.startsWith(u"tonsite://"_q)
|
||||
? QUrl(url)
|
||||
: QUrl::fromUserInput(url);
|
||||
if (HiddenUrlRequiresConfirmation(parsedUrl)
|
||||
&& !base::IsCtrlPressed()) {
|
||||
const auto my = context.value<ClickHandlerContext>();
|
||||
auto my = context.value<ClickHandlerContext>();
|
||||
auto openContext = context;
|
||||
const auto forceConfirmation = my.forceExternalUrlConfirmation
|
||||
&& my.ignoreIv;
|
||||
const auto skipConfirmation = base::IsCtrlPressed();
|
||||
if (forceConfirmation) {
|
||||
my.forceExternalUrlConfirmation = false;
|
||||
openContext = QVariant::fromValue(my);
|
||||
}
|
||||
const auto confirmAfterIvFallback
|
||||
= RequiresConfirmationAfterIvFallback(parsedUrl)
|
||||
&& !my.ignoreIv
|
||||
&& !skipConfirmation;
|
||||
const auto canTryIv = (my.sessionWindow.get() != nullptr);
|
||||
if (confirmAfterIvFallback && canTryIv) {
|
||||
my.forceExternalUrlConfirmation = true;
|
||||
openContext = QVariant::fromValue(my);
|
||||
}
|
||||
const auto open = [=] {
|
||||
UrlClickHandler::Open(url, openContext);
|
||||
};
|
||||
if (forceConfirmation
|
||||
|| (confirmAfterIvFallback && !canTryIv)
|
||||
|| (HiddenUrlRequiresConfirmation(parsedUrl)
|
||||
&& !skipConfirmation)) {
|
||||
if (!my.show) {
|
||||
Core::App().hideMediaView();
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ struct ClickHandlerContext {
|
||||
bool skipBotAutoLogin = false;
|
||||
bool botStartAutoSubmit = false;
|
||||
bool ignoreIv = false;
|
||||
bool forceExternalUrlConfirmation = false;
|
||||
bool dark = false;
|
||||
// Is filled from peer info.
|
||||
PeerData *peer = nullptr;
|
||||
|
||||
@@ -1026,7 +1026,12 @@ void Instance::openWithIvPreferred(
|
||||
const auto openExternal = [=] {
|
||||
auto my = context.value<ClickHandlerContext>();
|
||||
my.ignoreIv = true;
|
||||
UrlClickHandler::Open(uri, QVariant::fromValue(my));
|
||||
const auto updated = QVariant::fromValue(my);
|
||||
if (my.forceExternalUrlConfirmation) {
|
||||
HiddenUrlClickHandler::Open(uri, updated);
|
||||
} else {
|
||||
UrlClickHandler::Open(uri, updated);
|
||||
}
|
||||
};
|
||||
const auto parts = uri.split('#');
|
||||
if (parts.isEmpty() || parts[0].isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user