From 625ae87eea162e375303f319314fff65d65fb9f8 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 29 Oct 2023 10:12:48 +0400 Subject: [PATCH] Add "show-peer-id-below-about" option. --- .../SourceFiles/core/local_url_handlers.cpp | 15 +++++++++++++++ .../info/profile/info_profile_values.cpp | 19 +++++++++++++++++++ .../info/profile/info_profile_values.h | 2 ++ .../settings/settings_experimental.cpp | 2 ++ 4 files changed, 38 insertions(+) diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index e8121204d..d029a9a78 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -644,6 +644,17 @@ bool OpenExternalLink( context); } +bool CopyPeerId( + Window::SessionController *controller, + const Match &match, + const QVariant &context) { + TextUtilities::SetClipboardText(TextForMimeData{ match->captured(1) }); + if (controller) { + controller->showToast(tr::lng_text_copied(tr::now)); + } + return true; +} + void ExportTestChatTheme( not_null controller, not_null theme) { @@ -985,6 +996,10 @@ const std::vector &InternalUrlHandlers() { u"^url:(.+)$"_q, OpenExternalLink }, + { + u"^copy:(.+)$"_q, + CopyPeerId + } }; return Result; } diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.cpp b/Telegram/SourceFiles/info/profile/info_profile_values.cpp index 878366d15..198e73975 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_values.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_values.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "info/profile/info_profile_values.h" +#include "base/options.h" #include "info/profile/info_profile_badge.h" #include "core/application.h" #include "core/click_handler_types.h" @@ -37,6 +38,12 @@ namespace { using UpdateFlag = Data::PeerUpdate::Flag; +base::options::toggle ShowPeerIdBelowAbout({ + .id = kOptionShowPeerIdBelowAbout, + .name = "Show Peer IDs in Profile", + .description = "Show peer IDs from API below their Bio / Description.", +}); + auto PlainAboutValue(not_null peer) { return peer->session().changes().peerFlagsValue( peer, @@ -87,6 +94,8 @@ void StripExternalLinks(TextWithEntities &text) { } // namespace +const char kOptionShowPeerIdBelowAbout[] = "show-peer-id-below-about"; + rpl::producer NameValue(not_null peer) { return peer->session().changes().peerFlagsValue( peer, @@ -209,6 +218,16 @@ TextWithEntities AboutWithEntities( if (stripExternal) { StripExternalLinks(result); } + if (ShowPeerIdBelowAbout.value()) { + using namespace Ui::Text; + if (!result.empty()) { + result.append("\n"); + } + result.append(Italic(u"id: "_q)); + const auto raw = peer->id.value & PeerId::kChatTypeMask; + const auto id = QString::number(raw); + result.append(Link(Italic(id), "internal:copy:" + id)); + } return result; } diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.h b/Telegram/SourceFiles/info/profile/info_profile_values.h index b3a110fe4..67c9238fb 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_values.h +++ b/Telegram/SourceFiles/info/profile/info_profile_values.h @@ -35,6 +35,8 @@ enum class SharedMediaType : signed char; namespace Info::Profile { +extern const char kOptionShowPeerIdBelowAbout[]; + inline auto ToSingleLine() { return rpl::map([](const QString &text) { return TextUtilities::SingleLine(text); diff --git a/Telegram/SourceFiles/settings/settings_experimental.cpp b/Telegram/SourceFiles/settings/settings_experimental.cpp index 97447adf1..6104cabb1 100644 --- a/Telegram/SourceFiles/settings/settings_experimental.cpp +++ b/Telegram/SourceFiles/settings/settings_experimental.cpp @@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/launcher.h" #include "chat_helpers/tabbed_panel.h" #include "dialogs/dialogs_widget.h" +#include "info/profile/info_profile_values.h" #include "lang/lang_keys.h" #include "mainwindow.h" #include "media/player/media_player_instance.h" @@ -141,6 +142,7 @@ void SetupExperimental( addToggle(Dialogs::kOptionForumHideChatsList); addToggle(Core::kOptionFractionalScalingEnabled); addToggle(Window::kOptionViewProfileInChatsListContextMenu); + addToggle(Info::Profile::kOptionShowPeerIdBelowAbout); addToggle(Ui::GL::kOptionAllowLinuxNvidiaOpenGL); addToggle(Ui::kOptionUseSmallMsgBubbleRadius); addToggle(Media::Player::kOptionDisableAutoplayNext);