diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 301ed08d9..54dadc055 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2432,7 +2432,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ktg_settings_no_taskbar_flash" = "Disable taskbar flashing"; "ktg_settings_other" = "Other"; -"ktg_settings_show_chat_id" = "Show chat ID"; "ktg_profile_copy_id" = "Copy ID"; "ktg_profile_bot_id" = "Bot ID"; "ktg_profile_user_id" = "User ID"; @@ -2507,4 +2506,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ktg_settings_tray_icon_desc" = "If you don't like any of these icons, you can place icon.png in your profile folder.\n\nYou'll need to restart app to save changes."; +"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"; + // Keys finished diff --git a/Telegram/Resources/langs/rewrites/ru.json b/Telegram/Resources/langs/rewrites/ru.json index bfe8abb54..c48bcea05 100644 --- a/Telegram/Resources/langs/rewrites/ru.json +++ b/Telegram/Resources/langs/rewrites/ru.json @@ -66,7 +66,6 @@ "ktg_settings_system": "Система", "ktg_settings_no_taskbar_flash": "Отключить мигание на панели задач", "ktg_settings_other": "Прочие", - "ktg_settings_show_chat_id": "Показывать ID чата", "ktg_profile_copy_id": "Копировать ID", "ktg_profile_bot_id": "ID бота", "ktg_profile_user_id": "ID пользователя", @@ -115,5 +114,10 @@ "ktg_settings_tray_icon_orange": "Оранжевая", "ktg_settings_tray_icon_red": "Красная", "ktg_settings_tray_icon_legacy": "Старая", - "ktg_settings_tray_icon_desc": "Если вам не нравится ни одна из этих иконок, вы можете положить icon.png в вашу папку профиля.\n\nДля применения и просмотра изменений требуется перезапуск." + "ktg_settings_tray_icon_desc": "Если вам не нравится ни одна из этих иконок, вы можете положить icon.png в вашу папку профиля.\n\nДля применения и просмотра изменений требуется перезапуск.", + "ktg_settings_chat_id": "ID чата в профиле", + "ktg_settings_chat_id_desc": "Здесь можно выбрать желаемый вид ID.\n\nTelegram API использует ID как есть, а Bot API добавляет минус в начало для групп и -100 для каналов и супергрупп, чтобы уместить всё в одно поле.\n\nЕсли у вас открыта панель профиля, закройте её и откройте заново, чтобы увидеть изменения.", + "ktg_settings_chat_id_disable": "Скрыть", + "ktg_settings_chat_id_telegram": "Telegram API", + "ktg_settings_chat_id_bot": "Bot API" } diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index 639d388d4..9ec66fadf 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -414,6 +414,8 @@ struct Data { int CallOutputVolume = 100; int CallInputVolume = 100; bool CallAudioDuckingEnabled = true; + + base::Observable ChatIDFormatChanged; }; } // namespace internal @@ -542,4 +544,6 @@ DefineVar(Global, int, CallOutputVolume); DefineVar(Global, int, CallInputVolume); DefineVar(Global, bool, CallAudioDuckingEnabled); +DefineRefVar(Global, base::Observable, ChatIDFormatChanged); + } // namespace Global diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index 03bc47f79..3912b6068 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -240,6 +240,8 @@ DeclareVar(int, CallOutputVolume); DeclareVar(int, CallInputVolume); DeclareVar(bool, CallAudioDuckingEnabled); +DeclareRefVar(base::Observable, ChatIDFormatChanged); + } // namespace Global namespace Adaptive { diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 69d0faaaf..f55d40496 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -256,7 +256,7 @@ object_ptr DetailsFiller::setupInfo() { return result; }; if (const auto user = _peer->asUser()) { - if (cShowChatId()) { + if (cShowChatId() != 0) { if (user->isBot()) { addInfoOneLine( tr::ktg_profile_bot_id(), @@ -298,7 +298,7 @@ object_ptr DetailsFiller::setupInfo() { [=] { window->show(Box(EditContactBox, window, user)); }, tracker); } else { - if (cShowChatId()) { + if (cShowChatId() != 0) { if (_peer->isChat()) { addInfoOneLine( tr::ktg_profile_group_id(), diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.cpp b/Telegram/SourceFiles/info/profile/info_profile_values.cpp index 714e93814..0b91a1d4f 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_values.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_values.cpp @@ -27,6 +27,8 @@ namespace Info { namespace Profile { namespace { +constexpr auto kMaxChannelId = -1000000000000; + auto PlainBioValue(not_null user) { return Notify::PeerUpdateValue( user, @@ -46,7 +48,17 @@ auto PlainUsernameValue(not_null peer) { } // namespace rpl::producer IDValue(not_null peer) { - return rpl::single(QString::number(peer->bareId())) | Ui::Text::ToWithEntities(); + auto resultId = QString::number(peer->bareId()); + + if (cShowChatId() == 2) { + if (peer->isChannel()) { + resultId = QString::number(kMaxChannelId - peer->bareId()); + } else if (peer->isChat()) { + resultId = QString::number(-peer->bareId()); + } + } + + return rpl::single(resultId) | Ui::Text::ToWithEntities(); } rpl::producer NameValue(not_null peer) { diff --git a/Telegram/SourceFiles/kotato/json_settings.cpp b/Telegram/SourceFiles/kotato/json_settings.cpp index ab3b27b7b..518d52bde 100644 --- a/Telegram/SourceFiles/kotato/json_settings.cpp +++ b/Telegram/SourceFiles/kotato/json_settings.cpp @@ -314,10 +314,18 @@ bool Manager::readCustomFile() { cSetAlwaysShowScheduled(v); }); - ReadBoolOption(settings, "show_chat_id", [&](auto v) { - cSetShowChatId(v); + auto isShowChatIdSet = ReadIntOption(settings, "show_chat_id", [&](auto v) { + if (v >= 0 && v <= 2) { + cSetShowChatId(v); + } }); + if (!isShowChatIdSet) { + ReadBoolOption(settings, "show_chat_id", [&](auto v) { + cSetShowChatId(v ? 1 : 0); + }); + } + ReadOption(settings, "net_speed_boost", [&](auto v) { if (v.isString()) { diff --git a/Telegram/SourceFiles/kotato/settings.cpp b/Telegram/SourceFiles/kotato/settings.cpp index f8497b4f1..c478e8f91 100644 --- a/Telegram/SourceFiles/kotato/settings.cpp +++ b/Telegram/SourceFiles/kotato/settings.cpp @@ -54,7 +54,7 @@ rpl::producer AdaptiveBubblesChanges() { } bool gAlwaysShowScheduled = false; -bool gShowChatId = false; +int gShowChatId = 0; int gNetSpeedBoost = 0; int gNetRequestsCount = 2; diff --git a/Telegram/SourceFiles/kotato/settings.h b/Telegram/SourceFiles/kotato/settings.h index 8823329f2..06b88372e 100644 --- a/Telegram/SourceFiles/kotato/settings.h +++ b/Telegram/SourceFiles/kotato/settings.h @@ -44,7 +44,7 @@ void SetAdaptiveBubbles(bool enabled); [[nodiscard]] rpl::producer AdaptiveBubblesChanges(); DeclareSetting(bool, AlwaysShowScheduled); -DeclareSetting(bool, ShowChatId); +DeclareSetting(int, ShowChatId); DeclareSetting(int, NetSpeedBoost); DeclareSetting(int, NetRequestsCount); diff --git a/Telegram/SourceFiles/kotato/settings_menu.cpp b/Telegram/SourceFiles/kotato/settings_menu.cpp index 519a32664..e831b33c3 100644 --- a/Telegram/SourceFiles/kotato/settings_menu.cpp +++ b/Telegram/SourceFiles/kotato/settings_menu.cpp @@ -106,6 +106,23 @@ QString TrayIconLabel(int icon) { return QString(); } +QString ChatIdLabel(int option) { + switch (option) { + case 0: + return tr::ktg_settings_chat_id_disable(tr::now); + + case 1: + return tr::ktg_settings_chat_id_telegram(tr::now); + + case 2: + return tr::ktg_settings_chat_id_bot(tr::now); + + default: + Unexpected("Option in Settings::ChatIdLabel."); + } + return QString(); +} + } // namespace #define SettingsMenuCSwitch(LangKey, Option) AddButton( \ @@ -373,7 +390,43 @@ void SetupKotatoOther(not_null container) { AddSubsectionTitle(container, tr::ktg_settings_other()); SettingsMenuCSwitch(ktg_settings_show_phone_number, ShowPhoneInDrawer); - SettingsMenuCSwitch(ktg_settings_show_chat_id, ShowChatId); + + const QMap chatIdOptions = { + { 0, ChatIdLabel(0) }, + { 1, ChatIdLabel(1) }, + { 2, ChatIdLabel(2) }, + }; + + const auto chatIdButton = container->add( + object_ptr