From 3cb33f08257e912dc131d9431e47dbb899dbefbc Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 10 Oct 2024 12:10:41 +0400 Subject: [PATCH] Custom "Copy ID" for peer ID context menu. --- Telegram/SourceFiles/core/application.cpp | 9 ++++++++- .../info/profile/info_profile_actions.cpp | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 5810e8eb3..b91813e16 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -1162,7 +1162,14 @@ bool Application::openCustomUrl( || passcodeLocked()) { return false; } - const auto command = base::StringViewMid(urlTrimmed, protocol.size(), 8192); + static const auto kTagExp = QRegularExpression( + u"\\~[a-zA-Z0-9_\\-]+\\~:"_q); + auto skip = protocol.size(); + const auto match = kTagExp.match(urlTrimmed, skip); + if (match.hasMatch()) { + skip += match.capturedLength(); + } + const auto command = base::StringViewMid(urlTrimmed, skip, 8192); const auto my = context.value(); const auto controller = my.sessionWindow.get() ? my.sessionWindow.get() diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 8a3380726..f23cf8c10 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -185,7 +185,7 @@ base::options::toggle ShowPeerIdBelowAbout({ const auto raw = peer->id.value & PeerId::kChatTypeMask; value.append(Link( Italic(Lang::FormatCountDecimal(raw)), - "internal:copy:" + QString::number(raw))); + "internal:~peer_id~:copy:" + QString::number(raw))); return std::move(value); }); } @@ -979,6 +979,20 @@ object_ptr DetailsFiller::setupInfo() { state->labelText = std::move(text); label->setContextMenuHook([=]( Ui::FlatLabel::ContextMenuRequest request) { + if (request.link) { + const auto &url = request.link->url(); + if (url.startsWith(u"internal:~peer_id~:"_q)) { + const auto weak = base::make_weak(controller); + request.menu->addAction(u"Copy ID"_q, [=] { + Core::App().openInternalUrl( + url, + QVariant::fromValue(ClickHandlerContext{ + .sessionWindow = weak, + })); + }); + return; + } + } label->fillContextMenu(request); if (Ui::SkipTranslate(state->labelText.current())) { return;