mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 07:33:52 +02:00
Highlight telegram/telegraph/telescope links.
This commit is contained in:
parent
4432863612
commit
9592e7dfc8
3 changed files with 10 additions and 8 deletions
|
@ -25,14 +25,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include <QtGui/QGuiApplication>
|
#include <QtGui/QGuiApplication>
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
bool UrlRequiresConfirmation(const QUrl &url) {
|
bool UrlRequiresConfirmation(const QUrl &url) {
|
||||||
using namespace qthelp;
|
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) {
|
void HiddenUrlClickHandler::Open(QString url, QVariant context) {
|
||||||
url = Core::TryConvertUrlToLocal(url);
|
url = Core::TryConvertUrlToLocal(url);
|
||||||
|
@ -48,7 +48,7 @@ void HiddenUrlClickHandler::Open(QString url, QVariant context) {
|
||||||
open();
|
open();
|
||||||
} else {
|
} else {
|
||||||
const auto parsedUrl = QUrl::fromUserInput(url);
|
const auto parsedUrl = QUrl::fromUserInput(url);
|
||||||
if (UrlRequiresConfirmation(url)
|
if (UrlRequiresConfirmation(parsedUrl)
|
||||||
&& QGuiApplication::keyboardModifiers() != Qt::ControlModifier) {
|
&& QGuiApplication::keyboardModifiers() != Qt::ControlModifier) {
|
||||||
Core::App().hideMediaView();
|
Core::App().hideMediaView();
|
||||||
const auto displayed = parsedUrl.isValid()
|
const auto displayed = parsedUrl.isValid()
|
||||||
|
|
|
@ -13,6 +13,8 @@ namespace Main {
|
||||||
class Session;
|
class Session;
|
||||||
} // namespace Main
|
} // namespace Main
|
||||||
|
|
||||||
|
[[nodiscard]] bool UrlRequiresConfirmation(const QUrl &url);
|
||||||
|
|
||||||
class HiddenUrlClickHandler : public UrlClickHandler {
|
class HiddenUrlClickHandler : public UrlClickHandler {
|
||||||
public:
|
public:
|
||||||
HiddenUrlClickHandler(QString url) : UrlClickHandler(url, false) {
|
HiddenUrlClickHandler(QString url) : UrlClickHandler(url, false) {
|
||||||
|
|
|
@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "info/profile/info_profile_values.h"
|
#include "info/profile/info_profile_values.h"
|
||||||
|
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "core/local_url_handlers.h"
|
#include "core/click_handler_types.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "ui/wrap/slide_wrap.h"
|
#include "ui/wrap/slide_wrap.h"
|
||||||
#include "ui/text/text_utilities.h"
|
#include "ui/text/text_utilities.h"
|
||||||
|
@ -50,7 +50,7 @@ auto PlainUsernameValue(not_null<PeerData*> peer) {
|
||||||
|
|
||||||
void StripExternalLinks(TextWithEntities &text) {
|
void StripExternalLinks(TextWithEntities &text) {
|
||||||
const auto local = [](const QString &url) {
|
const auto local = [](const QString &url) {
|
||||||
return Core::TryConvertUrlToLocal(url).startsWith(qstr("tg://"));
|
return !UrlRequiresConfirmation(QUrl::fromUserInput(url));
|
||||||
};
|
};
|
||||||
const auto notLocal = [&](const EntityInText &entity) {
|
const auto notLocal = [&](const EntityInText &entity) {
|
||||||
if (entity.type() == EntityType::CustomUrl) {
|
if (entity.type() == EntityType::CustomUrl) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue