diff --git a/Telegram/SourceFiles/api/api_text_entities.cpp b/Telegram/SourceFiles/api/api_text_entities.cpp index 93a1f467cc..87af7a77a3 100644 --- a/Telegram/SourceFiles/api/api_text_entities.cpp +++ b/Telegram/SourceFiles/api/api_text_entities.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "history/history_item.h" #include "main/main_session.h" +#include "ui/basic_click_handlers.h" namespace Api { namespace { @@ -306,11 +307,15 @@ MTPVector EntitiesToMTP( v.push_back(MTP_messageEntityUrl(offset, length)); } break; case EntityType::CustomUrl: { + const auto external = UrlClickHandler::ExternalUrlFromInternalUrl( + entity.data()); v.push_back( MTP_messageEntityTextUrl( offset, length, - MTP_string(entity.data()))); + MTP_string(external.isEmpty() + ? entity.data() + : external))); } break; case EntityType::Email: { v.push_back(MTP_messageEntityEmail(offset, length)); diff --git a/Telegram/SourceFiles/core/click_handler_types.cpp b/Telegram/SourceFiles/core/click_handler_types.cpp index 9db4f7913f..cf92ce618c 100644 --- a/Telegram/SourceFiles/core/click_handler_types.cpp +++ b/Telegram/SourceFiles/core/click_handler_types.cpp @@ -232,17 +232,30 @@ bool UrlRequiresConfirmation(const QUrl &url) { } QString HiddenUrlClickHandler::copyToClipboardText() const { - return url().startsWith(u"internal:url:"_q) - ? url().mid(u"internal:url:"_q.size()) - : url(); + const auto original = originalUrl(); + const auto originalExternal = UrlClickHandler::ExternalUrlFromInternalUrl( + original); + if (!originalExternal.isEmpty()) { + return originalExternal; + } + const auto value = url(); + const auto external = UrlClickHandler::ExternalUrlFromInternalUrl(value); + return external.isEmpty() ? value : external; } QString HiddenUrlClickHandler::copyToClipboardContextItemText() const { - return url().isEmpty() + const auto original = originalUrl(); + const auto originalExternal = UrlClickHandler::ExternalUrlFromInternalUrl( + original); + const auto value = originalExternal.isEmpty() ? url() : original; + const auto external = originalExternal.isEmpty() + ? UrlClickHandler::ExternalUrlFromInternalUrl(value) + : originalExternal; + return value.isEmpty() ? QString() - : !url().startsWith(u"internal:"_q) + : !value.startsWith(u"internal:"_q) ? UrlClickHandler::copyToClipboardContextItemText() - : url().startsWith(u"internal:url:"_q) + : !external.isEmpty() ? UrlClickHandler::copyToClipboardContextItemText() : QString(); } @@ -253,6 +266,10 @@ QString HiddenUrlClickHandler::dragText() const { } void HiddenUrlClickHandler::Open(QString url, QVariant context) { + if (const auto external = UrlClickHandler::ExternalUrlFromInternalUrl(url); + !external.isEmpty()) { + url = external; + } url = Core::TryConvertUrlToLocal(url); if (Core::InternalPassportOrOAuthLink(url)) { return; @@ -427,7 +444,13 @@ void BotGameUrlClickHandler::onClick(ClickContext context) const { } auto HiddenUrlClickHandler::getTextEntity() const -> TextEntity { - return { EntityType::CustomUrl, url() }; + const auto original = originalUrl(); + return { + EntityType::CustomUrl, + UrlClickHandler::ExternalUrlFromInternalUrl(original).isEmpty() + ? url() + : original + }; } QString MentionClickHandler::copyToClipboardContextItemText() const { diff --git a/Telegram/SourceFiles/core/click_handler_types.h b/Telegram/SourceFiles/core/click_handler_types.h index fc488070bc..887f3a3ecd 100644 --- a/Telegram/SourceFiles/core/click_handler_types.h +++ b/Telegram/SourceFiles/core/click_handler_types.h @@ -77,7 +77,12 @@ public: void onClick(ClickContext context) const override { const auto button = context.button; if (button == Qt::LeftButton || button == Qt::MiddleButton) { - Open(url(), context.other); + const auto original = originalUrl(); + Open( + UrlClickHandler::ExternalUrlFromInternalUrl(original).isEmpty() + ? url() + : original, + context.other); } } diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp index cbce62e123..bef0de7dcc 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp @@ -746,14 +746,15 @@ TextWithEntities GenerateDefaultBannedRightsChangeText( not_null channel, const MTPForumTopic &topic) { return topic.match([&](const MTPDforumTopic &data) { + const auto url = u"https://t.me/c/%1/%2"_q.arg( + peerToChannel(channel->id).bare).arg( + data.vid().v); return tr::link( Data::ForumTopicIconWithTitle( data.vid().v, data.vicon_emoji_id().value_or_empty(), qs(data.vtitle())), - u"internal:url:https://t.me/c/%1/%2"_q.arg( - peerToChannel(channel->id).bare).arg( - data.vid().v)); + UrlClickHandler::EncodeInternalWrappedUrl(url)); }, [](const MTPDforumTopicDeleted &) { return TextWithEntities{ u"Deleted"_q }; }); diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index d812dbdf84..5873a60e00 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -6065,9 +6065,10 @@ void HistoryItem::setServiceMessageByAction(const MTPmessageAction &action) { auto prepareTopicCreate = [&](const MTPDmessageActionTopicCreate &action) { auto result = PreparedServiceText(); - const auto topicUrl = u"internal:url:https://t.me/c/%1/%2"_q - .arg(peerToChannel(_history->peer->id).bare) - .arg(id.bare); + const auto topicUrl = UrlClickHandler::EncodeInternalWrappedUrl( + u"https://t.me/c/%1/%2"_q + .arg(peerToChannel(_history->peer->id).bare) + .arg(id.bare)); result.text = tr::lng_action_topic_created( tr::now, lt_topic, diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index a29739a9d8..2adce81651 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -538,8 +538,7 @@ public: [[nodiscard]] Data::Media *media() const { return _media.get(); } - [[nodiscard]] auto richPage() const - -> std::shared_ptr; + [[nodiscard]] std::shared_ptr richPage() const; [[nodiscard]] bool computeDropForwardedInfo() const; void setText(TextWithEntities textWithEntities); void setRichPage(std::shared_ptr page); diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index f76e9e7a11..42ba1d6bb2 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -1683,9 +1683,10 @@ auto Element::contextDependentServiceText() -> TextWithLinks { return {}; } const auto from = item->from(); - const auto topicUrl = u"internal:url:https://t.me/c/%1/%2"_q - .arg(peerToChannel(peerId).bare) - .arg(topicRootId.bare); + const auto topicUrl = UrlClickHandler::EncodeInternalWrappedUrl( + u"https://t.me/c/%1/%2"_q + .arg(peerToChannel(peerId).bare) + .arg(topicRootId.bare)); const auto fromLink = [&](int index) { return tr::link(from->name(), index); }; diff --git a/Telegram/lib_ui b/Telegram/lib_ui index ebaddb2d4b..8a05fabfc6 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit ebaddb2d4bd1e13763c9107b7585398d6cb65eb2 +Subproject commit 8a05fabfc660c5b5b4b95b91220e73e4e13dc5e9