From 9592e7dfc8385fa49701c5cc299ac238a7d6ed61 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 2 Nov 2020 09:34:54 +0300 Subject: [PATCH] Highlight telegram/telegraph/telescope links. --- Telegram/SourceFiles/core/click_handler_types.cpp | 12 ++++++------ Telegram/SourceFiles/core/click_handler_types.h | 2 ++ .../SourceFiles/info/profile/info_profile_values.cpp | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Telegram/SourceFiles/core/click_handler_types.cpp b/Telegram/SourceFiles/core/click_handler_types.cpp index b0b71bfa5b..793ea5ae94 100644 --- a/Telegram/SourceFiles/core/click_handler_types.cpp +++ b/Telegram/SourceFiles/core/click_handler_types.cpp @@ -25,14 +25,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include -namespace { - bool UrlRequiresConfirmation(const QUrl &url) { using namespace qthelp; - return !regex_match(qsl("(^|\\.)(telegram\\.org|telegra\\.ph|telesco\\.pe)$"), url.host(), RegExOption::CaseInsensitive); -} -} // namespace + return !regex_match( + "(^|\\.)(telegram\\.(org|me|dog)|t\\.me|telegra\\.ph|telesco\\.pe)$", + url.host(), + RegExOption::CaseInsensitive); +} void HiddenUrlClickHandler::Open(QString url, QVariant context) { url = Core::TryConvertUrlToLocal(url); @@ -48,7 +48,7 @@ void HiddenUrlClickHandler::Open(QString url, QVariant context) { open(); } else { const auto parsedUrl = QUrl::fromUserInput(url); - if (UrlRequiresConfirmation(url) + if (UrlRequiresConfirmation(parsedUrl) && QGuiApplication::keyboardModifiers() != Qt::ControlModifier) { Core::App().hideMediaView(); const auto displayed = parsedUrl.isValid() diff --git a/Telegram/SourceFiles/core/click_handler_types.h b/Telegram/SourceFiles/core/click_handler_types.h index 136c236d39..bed3a6becc 100644 --- a/Telegram/SourceFiles/core/click_handler_types.h +++ b/Telegram/SourceFiles/core/click_handler_types.h @@ -13,6 +13,8 @@ namespace Main { class Session; } // namespace Main +[[nodiscard]] bool UrlRequiresConfirmation(const QUrl &url); + class HiddenUrlClickHandler : public UrlClickHandler { public: HiddenUrlClickHandler(QString url) : UrlClickHandler(url, false) { diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.cpp b/Telegram/SourceFiles/info/profile/info_profile_values.cpp index 7c74ebf8dd..289abaf04e 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_values.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_values.cpp @@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/profile/info_profile_values.h" #include "core/application.h" -#include "core/local_url_handlers.h" +#include "core/click_handler_types.h" #include "main/main_session.h" #include "ui/wrap/slide_wrap.h" #include "ui/text/text_utilities.h" @@ -50,7 +50,7 @@ auto PlainUsernameValue(not_null peer) { void StripExternalLinks(TextWithEntities &text) { const auto local = [](const QString &url) { - return Core::TryConvertUrlToLocal(url).startsWith(qstr("tg://")); + return !UrlRequiresConfirmation(QUrl::fromUserInput(url)); }; const auto notLocal = [&](const EntityInText &entity) { if (entity.type() == EntityType::CustomUrl) {