From ee6b045c2c4571b6c061c519c37a9287fe38010a Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Fri, 26 Aug 2022 21:59:40 +0300 Subject: [PATCH] [Option][GUI] Show chat ID --- Telegram/Resources/langs/rewrites/en.json | 16 +++++ Telegram/SourceFiles/boxes/boxes.style | 5 ++ .../info/profile/info_profile_actions.cpp | 67 +++++++++++++++++++ .../info/profile/info_profile_values.cpp | 27 ++++++++ .../info/profile/info_profile_values.h | 4 ++ .../SourceFiles/kotato/kotato_settings.cpp | 4 ++ .../kotato/kotato_settings_menu.cpp | 50 ++++++++++++++ 7 files changed, 173 insertions(+) diff --git a/Telegram/Resources/langs/rewrites/en.json b/Telegram/Resources/langs/rewrites/en.json index 3cbf7725c..ab91d5b32 100644 --- a/Telegram/Resources/langs/rewrites/en.json +++ b/Telegram/Resources/langs/rewrites/en.json @@ -43,10 +43,26 @@ "ktg_settings_network": "Network", "ktg_settings_system": "System", "ktg_settings_other": "Other", + "ktg_profile_copy_id": "Copy ID", + "ktg_profile_bot_id": "Bot ID", + "ktg_profile_user_id": "User ID", + "ktg_profile_group_id": "Group ID", + "ktg_profile_supergroup_id": "Supergroup ID", + "ktg_profile_channel_id": "Channel ID", "ktg_settings_adaptive_bubbles": "Adaptive bubbles", "ktg_settings_filters": "Folders", "ktg_settings_messages": "Messages", + "ktg_settings_chat_id": "Chat ID in profile", + "ktg_settings_chat_id_desc": "You can choose desired format here.\n\nTelegram API uses IDs as-is, but Bot API adds minus in the beginning for groups, and -100 for channels and supergroups to fit it in one field.\n\nIf you have profile panel opened, re-open it to see changes.", + "ktg_settings_chat_id_disable": "Hide", + "ktg_settings_chat_id_telegram": "Telegram API", + "ktg_settings_chat_id_bot": "Bot API", "ktg_settings_monospace_large_bubbles": "Expand bubbles with monospace", + "ktg_bot_id_copied": "Bot ID copied to clipboard.", + "ktg_user_id_copied": "User ID copied to clipboard.", + "ktg_group_id_copied": "Group ID copied to clipboard.", + "ktg_supergroup_id_copied": "Supergroup ID copied to clipboard.", + "ktg_channel_id_copied": "Channel ID copied to clipboard.", "ktg_settings_forward": "Forward", "ktg_in_app_update_disabled": "In-app updater is disabled.", "dummy_last_string": "" diff --git a/Telegram/SourceFiles/boxes/boxes.style b/Telegram/SourceFiles/boxes/boxes.style index 634a607bf..5c042c27e 100644 --- a/Telegram/SourceFiles/boxes/boxes.style +++ b/Telegram/SourceFiles/boxes/boxes.style @@ -1010,6 +1010,11 @@ infoLabeledOneLine: FlatLabel(defaultFlatLabel) { } margin: margins(5px, 5px, 5px, 5px); } +infoLabeledOneLineInline: FlatLabel(infoLabeledOneLine) { + palette: TextPalette(defaultTextPalette) { + linkFg: windowFg; + } +} infoLabelSkip: 2px; infoLabeled: FlatLabel(infoLabeledOneLine) { minWidth: 180px; diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 4dbd1fd33..71ed7f79d 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "info/profile/info_profile_actions.h" +#include "kotato/kotato_lang.h" +#include "kotato/kotato_settings.h" #include "api/api_blocked_peers.h" #include "api/api_chat_participants.h" #include "apiwrap.h" @@ -1030,8 +1032,44 @@ object_ptr DetailsFiller::setupInfo() { result.text->setContextCopyText(contextCopyText); return result; }; + auto addInfoOneLineInline = [&]( + rpl::producer &&label, + rpl::producer &&text, + const QString &contextCopyText) { + auto result = addInfoLine( + std::move(label), + std::move(text), + st::infoLabeledOneLineInline); + result->setContextCopyText(contextCopyText); + return result; + }; if (const auto user = _peer->asUser()) { const auto controller = _controller->parentController(); + if (::Kotato::JsonSettings::GetInt("show_chat_id") != 0) { + auto idDrawableText = IDValue( + user + ) | rpl::map([](TextWithEntities &&text) { + return Ui::Text::Link(text.text); + }); + auto idInfo = addInfoOneLineInline( + (user->isBot() + ? rktr("ktg_profile_bot_id") + : rktr("ktg_profile_user_id")), + std::move(idDrawableText), + ktr("ktg_profile_copy_id")); + + idInfo->setClickHandlerFilter([user](auto&&...) { + const auto idText = IDString(user); + if (!idText.isEmpty()) { + QGuiApplication::clipboard()->setText(idText); + Ui::Toast::Show(user->isBot() + ? ktr("ktg_bot_id_copied") + : ktr("ktg_user_id_copied")); + } + return false; + }); + } + if (user->session().supportMode()) { addInfoLineGeneric( user->session().supportHelper().infoLabelValue(user), @@ -1151,6 +1189,35 @@ object_ptr DetailsFiller::setupInfo() { [=] { controller->window().show(Box(EditContactBox, controller, user)); }, tracker); } else { + if (::Kotato::JsonSettings::GetInt("show_chat_id") != 0) { + auto idDrawableText = IDValue( + _peer + ) | rpl::map([](TextWithEntities &&text) { + return Ui::Text::Link(text.text); + }); + auto idInfo = addInfoOneLineInline( + (_peer->isChat() + ? rktr("ktg_profile_group_id") + : _peer->isMegagroup() + ? rktr("ktg_profile_supergroup_id") + : rktr("ktg_profile_channel_id")), + std::move(idDrawableText), + ktr("ktg_profile_copy_id")); + + idInfo->setClickHandlerFilter([peer = _peer](auto&&...) { + const auto idText = IDString(peer); + if (!idText.isEmpty()) { + QGuiApplication::clipboard()->setText(idText); + Ui::Toast::Show(peer->isChat() + ? ktr("ktg_group_id_copied") + : peer->isMegagroup() + ? ktr("ktg_supergroup_id_copied") + : ktr("ktg_channel_id_copied")); + } + return false; + }); + } + const auto topicRootId = _topic ? _topic->rootId() : 0; const auto addToLink = topicRootId ? ('/' + QString::number(topicRootId.bare)) diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.cpp b/Telegram/SourceFiles/info/profile/info_profile_values.cpp index 3a0f9566e..463d6d294 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 "kotato/kotato_settings.h" #include "api/api_chat_participants.h" #include "apiwrap.h" #include "info/profile/info_profile_phone_menu.h" @@ -40,6 +41,8 @@ namespace Info { namespace Profile { namespace { +constexpr auto kMaxChannelId = -1000000000000; + using UpdateFlag = Data::PeerUpdate::Flag; auto PlainAboutValue(not_null peer) { @@ -92,6 +95,30 @@ void StripExternalLinks(TextWithEntities &text) { } // namespace +QString IDString(not_null peer) { + auto resultId = QString::number(peerIsUser(peer->id) + ? peerToUser(peer->id).bare + : peerIsChat(peer->id) + ? peerToChat(peer->id).bare + : peerIsChannel(peer->id) + ? peerToChannel(peer->id).bare + : peer->id.value); + + if (::Kotato::JsonSettings::GetInt("show_chat_id") == 2) { + if (peer->isChannel()) { + resultId = QString::number(peerToChannel(peer->id).bare - kMaxChannelId).prepend("-"); + } else if (peer->isChat()) { + resultId = resultId.prepend("-"); + } + } + + return resultId; +} + +rpl::producer IDValue(not_null peer) { + return rpl::single(IDString(peer)) | Ui::Text::ToWithEntities(); +} + rpl::producer NameValue(not_null peer) { return peer->session().changes().peerFlagsValue( peer, diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.h b/Telegram/SourceFiles/info/profile/info_profile_values.h index 72d50055a..7a4c43fbc 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_values.h +++ b/Telegram/SourceFiles/info/profile/info_profile_values.h @@ -45,6 +45,10 @@ inline auto ToSingleLine() { rpl::producer> MigratedOrMeValue( not_null peer); +QString IDString(not_null peer); + +[[nodiscard]] rpl::producer IDValue( + not_null peer); [[nodiscard]] rpl::producer NameValue(not_null peer); [[nodiscard]] rpl::producer TitleValue( not_null topic); diff --git a/Telegram/SourceFiles/kotato/kotato_settings.cpp b/Telegram/SourceFiles/kotato/kotato_settings.cpp index 40a932a9a..ef853d8f4 100644 --- a/Telegram/SourceFiles/kotato/kotato_settings.cpp +++ b/Telegram/SourceFiles/kotato/kotato_settings.cpp @@ -245,6 +245,10 @@ const std::map> DefinitionMap { { "always_show_scheduled", { .type = SettingType::BoolSetting, .defaultValue = false, }}, + { "show_chat_id", { + .type = SettingType::IntSetting, + .defaultValue = 2, + .limitHandler = IntLimit(0, 2, 2), }}, }; using OldOptionKey = QString; diff --git a/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp b/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp index 333d81cc3..9882eec70 100644 --- a/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp +++ b/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp @@ -49,6 +49,23 @@ namespace Settings { namespace { +QString ChatIdLabel(int option) { + switch (option) { + case 0: + return ktr("ktg_settings_chat_id_disable"); + + case 1: + return ktr("ktg_settings_chat_id_telegram"); + + case 2: + return ktr("ktg_settings_chat_id_bot"); + + default: + Unexpected("Option in Settings::ChatIdLabel."); + } + return QString(); +} + } // namespace #define SettingsMenuJsonSwitch(LangKey, Option) container->add(object_ptr