Option to select chat ID format
This commit is contained in:
parent
491681883d
commit
1ec8763b63
10 changed files with 99 additions and 11 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -414,6 +414,8 @@ struct Data {
|
|||
int CallOutputVolume = 100;
|
||||
int CallInputVolume = 100;
|
||||
bool CallAudioDuckingEnabled = true;
|
||||
|
||||
base::Observable<void> ChatIDFormatChanged;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
|
@ -542,4 +544,6 @@ DefineVar(Global, int, CallOutputVolume);
|
|||
DefineVar(Global, int, CallInputVolume);
|
||||
DefineVar(Global, bool, CallAudioDuckingEnabled);
|
||||
|
||||
DefineRefVar(Global, base::Observable<void>, ChatIDFormatChanged);
|
||||
|
||||
} // namespace Global
|
||||
|
|
|
|||
|
|
@ -240,6 +240,8 @@ DeclareVar(int, CallOutputVolume);
|
|||
DeclareVar(int, CallInputVolume);
|
||||
DeclareVar(bool, CallAudioDuckingEnabled);
|
||||
|
||||
DeclareRefVar(base::Observable<void>, ChatIDFormatChanged);
|
||||
|
||||
} // namespace Global
|
||||
|
||||
namespace Adaptive {
|
||||
|
|
|
|||
|
|
@ -256,7 +256,7 @@ object_ptr<Ui::RpWidget> 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<Ui::RpWidget> DetailsFiller::setupInfo() {
|
|||
[=] { window->show(Box(EditContactBox, window, user)); },
|
||||
tracker);
|
||||
} else {
|
||||
if (cShowChatId()) {
|
||||
if (cShowChatId() != 0) {
|
||||
if (_peer->isChat()) {
|
||||
addInfoOneLine(
|
||||
tr::ktg_profile_group_id(),
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ namespace Info {
|
|||
namespace Profile {
|
||||
namespace {
|
||||
|
||||
constexpr auto kMaxChannelId = -1000000000000;
|
||||
|
||||
auto PlainBioValue(not_null<UserData*> user) {
|
||||
return Notify::PeerUpdateValue(
|
||||
user,
|
||||
|
|
@ -46,7 +48,17 @@ auto PlainUsernameValue(not_null<PeerData*> peer) {
|
|||
} // namespace
|
||||
|
||||
rpl::producer<TextWithEntities> IDValue(not_null<PeerData*> 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<TextWithEntities> NameValue(not_null<PeerData*> peer) {
|
||||
|
|
|
|||
|
|
@ -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()) {
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ rpl::producer<bool> AdaptiveBubblesChanges() {
|
|||
}
|
||||
|
||||
bool gAlwaysShowScheduled = false;
|
||||
bool gShowChatId = false;
|
||||
int gShowChatId = 0;
|
||||
|
||||
int gNetSpeedBoost = 0;
|
||||
int gNetRequestsCount = 2;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ void SetAdaptiveBubbles(bool enabled);
|
|||
[[nodiscard]] rpl::producer<bool> AdaptiveBubblesChanges();
|
||||
|
||||
DeclareSetting(bool, AlwaysShowScheduled);
|
||||
DeclareSetting(bool, ShowChatId);
|
||||
DeclareSetting(int, ShowChatId);
|
||||
|
||||
DeclareSetting(int, NetSpeedBoost);
|
||||
DeclareSetting(int, NetRequestsCount);
|
||||
|
|
|
|||
|
|
@ -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<Ui::VerticalLayout*> container) {
|
|||
AddSubsectionTitle(container, tr::ktg_settings_other());
|
||||
|
||||
SettingsMenuCSwitch(ktg_settings_show_phone_number, ShowPhoneInDrawer);
|
||||
SettingsMenuCSwitch(ktg_settings_show_chat_id, ShowChatId);
|
||||
|
||||
const QMap<int, QString> chatIdOptions = {
|
||||
{ 0, ChatIdLabel(0) },
|
||||
{ 1, ChatIdLabel(1) },
|
||||
{ 2, ChatIdLabel(2) },
|
||||
};
|
||||
|
||||
const auto chatIdButton = container->add(
|
||||
object_ptr<Button>(
|
||||
container,
|
||||
tr::ktg_settings_chat_id(),
|
||||
st::settingsButton));
|
||||
auto chatIdText = rpl::single(
|
||||
rpl::empty_value()
|
||||
) | rpl::then(base::ObservableViewer(
|
||||
Global::RefChatIDFormatChanged()
|
||||
)) | rpl::map([] {
|
||||
return ChatIdLabel(cShowChatId());
|
||||
});
|
||||
CreateRightLabel(
|
||||
chatIdButton,
|
||||
std::move(chatIdText),
|
||||
st::settingsButton,
|
||||
tr::ktg_settings_chat_id());
|
||||
chatIdButton->addClickHandler([=] {
|
||||
Ui::show(Box<::Kotato::RadioBox>(
|
||||
tr::ktg_settings_chat_id(tr::now),
|
||||
tr::ktg_settings_chat_id_desc(tr::now),
|
||||
cShowChatId(),
|
||||
chatIdOptions,
|
||||
[=] (int value) {
|
||||
cSetShowChatId(value);
|
||||
::Kotato::JsonSettings::Write();
|
||||
Global::RefChatIDFormatChanged().notify();
|
||||
}));
|
||||
});
|
||||
|
||||
SettingsMenuCSwitch(ktg_settings_call_confirm, ConfirmBeforeCall);
|
||||
|
||||
AddSkip(container);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue