From ac9ba74952e635fa957d8d1d715d1419014b1309 Mon Sep 17 00:00:00 2001 From: xmdn <72883689+xmdnx@users.noreply.github.com> Date: Sat, 24 Feb 2024 22:30:58 +0300 Subject: [PATCH] added seconds in time for chats (w/out translations as for now) --- .../SourceFiles/dialogs/ui/dialogs_layout.cpp | 8 +++++++- .../SourceFiles/history/history_inner_widget.cpp | 8 +++++++- Telegram/SourceFiles/history/history_item.cpp | 6 +++++- .../history/view/history_view_bottom_info.cpp | 6 +++++- .../history/view/history_view_list_widget.cpp | 8 +++++++- .../history/view/media/history_view_call.cpp | 6 +++++- .../media/player/media_player_widget.cpp | 8 +++++++- .../rabbit/settings/rabbit_settings.cpp | 3 +++ .../rabbit/settings_menu/rabbit_settings_menu.cpp | 15 +++++++++++++++ 9 files changed, 61 insertions(+), 7 deletions(-) diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp b/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp index d3c9ab4386479..6e97ca9c9f364 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp @@ -7,6 +7,8 @@ For license and copyright information please follow this link: */ #include "dialogs/ui/dialogs_layout.h" +#include "rabbit/settings/rabbit_settings.h" + #include "data/data_drafts.h" #include "data/data_forum_topic.h" #include "data/data_saved_sublist.h" @@ -94,7 +96,11 @@ void PaintRowDate( const auto dt = [&] { if ((lastDate == nowDate) || (qAbs(lastTime.secsTo(now)) < kRecentlyInSeconds)) { - return QLocale().toString(lastTime.time(), QLocale::ShortFormat); + return QLocale().toString( + lastTime.time(), + RabbitSettings::JsonSettings::GetBool("show_seconds") + ? QLocale::system().timeFormat(QLocale::LongFormat).remove(" t") + : QLocale::system().timeFormat(QLocale::ShortFormat)); } else if (qAbs(lastDate.daysTo(nowDate)) < 7) { return langDayOfWeek(lastDate); } else { diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 371527b5885f9..6298f73c9596b 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -7,6 +7,8 @@ For license and copyright information please follow this link: */ #include "history/history_inner_widget.h" +#include "rabbit/settings/rabbit_settings.h" + #include "core/file_utilities.h" #include "core/click_handler_types.h" #include "history/history_item_helpers.h" @@ -2853,7 +2855,11 @@ TextForMimeData HistoryInner::getSelectedText() const { const auto i = texts.emplace(item->position(), Part{ .name = item->author()->name(), .time = QString(", [%1]\n").arg( - QLocale().toString(ItemDateTime(item), QLocale::ShortFormat)), + QLocale().toString( + ItemDateTime(item), + RabbitSettings::JsonSettings::GetBool("show_seconds") + ? QLocale::system().timeFormat(QLocale::LongFormat).remove(" t") + : QLocale::system().timeFormat(QLocale::ShortFormat))), .unwrapped = std::move(unwrapped), }).first; fullSize += i->second.name.size() diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index e5905e16dc6a9..aac5b84835e79 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -7,6 +7,8 @@ For license and copyright information please follow this link: */ #include "history/history_item.h" +#include "rabbit/settings/rabbit_settings.h" + #include "lang/lang_keys.h" #include "mainwidget.h" #include "calls/calls_instance.h" // Core::App().calls().joinGroupCall. @@ -5323,7 +5325,9 @@ PreparedServiceText HistoryItem::prepareCallScheduledText( }; const auto time = QLocale().toString( scheduled.time(), - QLocale::ShortFormat); + RabbitSettings::JsonSettings::GetBool("show_seconds") + ? QLocale::system().timeFormat(QLocale::LongFormat).remove(" t") + : QLocale::system().timeFormat(QLocale::ShortFormat)); const auto prepareGeneric = [&] { prepareWithDate(tr::lng_group_call_starts_date( tr::now, diff --git a/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp b/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp index e1383d0a7f921..db35db535b0af 100644 --- a/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp +++ b/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp @@ -7,6 +7,8 @@ For license and copyright information please follow this link: */ #include "history/view/history_view_bottom_info.h" +#include "rabbit/settings/rabbit_settings.h" + #include "ui/chat/message_bubble.h" #include "ui/chat/chat_style.h" #include "ui/effects/reaction_fly_animation.h" @@ -471,7 +473,9 @@ void BottomInfo::layoutDateText() { const auto prefix = !author.isEmpty() ? u", "_q : QString(); const auto date = edited + QLocale().toString( _data.date.time(), - QLocale::ShortFormat); + RabbitSettings::JsonSettings::GetBool("show_seconds") + ? QLocale::system().timeFormat(QLocale::LongFormat).remove(" t") + : QLocale::system().timeFormat(QLocale::ShortFormat)); const auto afterAuthor = prefix + date; const auto afterAuthorWidth = st::msgDateFont->width(afterAuthor); const auto authorWidth = st::msgDateFont->width(author); diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 78364e556652f..69d9beecd30eb 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -7,6 +7,8 @@ For license and copyright information please follow this link: */ #include "history/view/history_view_list_widget.h" +#include "rabbit/settings/rabbit_settings.h" + #include "base/unixtime.h" #include "base/qt/qt_key_modifiers.h" #include "base/qt/qt_common_adapters.h" @@ -2337,7 +2339,11 @@ TextForMimeData ListWidget::getSelectedText() const { not_null item, TextForMimeData &&unwrapped) { auto time = QString(", [%1]\n").arg( - QLocale().toString(ItemDateTime(item), QLocale::ShortFormat)); + QLocale().toString( + ItemDateTime(item), + RabbitSettings::JsonSettings::GetBool("show_seconds") + ? QLocale::system().timeFormat(QLocale::LongFormat).remove(" t") + : QLocale::system().timeFormat(QLocale::ShortFormat))); auto part = TextForMimeData(); auto size = item->author()->name().size() + time.size() diff --git a/Telegram/SourceFiles/history/view/media/history_view_call.cpp b/Telegram/SourceFiles/history/view/media/history_view_call.cpp index 0a8200c8dd0ad..09edfcb04508a 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_call.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_call.cpp @@ -7,6 +7,8 @@ For license and copyright information please follow this link: */ #include "history/view/media/history_view_call.h" +#include "rabbit/settings/rabbit_settings.h" + #include "lang/lang_keys.h" #include "ui/chat/chat_style.h" #include "ui/text/format_values.h" @@ -48,7 +50,9 @@ Call::Call( _text = Data::MediaCall::Text(item, _reason, _video); _status = QLocale().toString( parent->dateTime().time(), - QLocale::ShortFormat); + RabbitSettings::JsonSettings::GetBool("show_seconds") + ? QLocale::system().timeFormat(QLocale::LongFormat).remove(" t") + : QLocale::system().timeFormat(QLocale::ShortFormat)); if (_duration) { _status = tr::lng_call_duration_info( tr::now, diff --git a/Telegram/SourceFiles/media/player/media_player_widget.cpp b/Telegram/SourceFiles/media/player/media_player_widget.cpp index 0fb8705bf8257..cb557482a7f99 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.cpp +++ b/Telegram/SourceFiles/media/player/media_player_widget.cpp @@ -7,6 +7,8 @@ For license and copyright information please follow this link: */ #include "media/player/media_player_widget.h" +#include "rabbit/settings/rabbit_settings.h" + #include "platform/platform_specific.h" #include "data/data_document.h" #include "data/data_session.h" @@ -683,7 +685,11 @@ void Widget::handleSongChange() { const auto date = [item] { const auto parsed = ItemDateTime(item); const auto date = parsed.date(); - const auto time = QLocale().toString(parsed.time(), QLocale::ShortFormat); + const auto time = QLocale().toString( + parsed.time(), + RabbitSettings::JsonSettings::GetBool("show_seconds") + ? QLocale::system().timeFormat(QLocale::LongFormat).remove(" t") + : QLocale::system().timeFormat(QLocale::ShortFormat)); const auto today = QDateTime::currentDateTime().date(); if (date == today) { return tr::lng_player_message_today( diff --git a/Telegram/SourceFiles/rabbit/settings/rabbit_settings.cpp b/Telegram/SourceFiles/rabbit/settings/rabbit_settings.cpp index 047b56fadb91e..684dd0f15bffd 100644 --- a/Telegram/SourceFiles/rabbit/settings/rabbit_settings.cpp +++ b/Telegram/SourceFiles/rabbit/settings/rabbit_settings.cpp @@ -276,6 +276,9 @@ const std::map> DefinitionMap { .type = SettingType::IntSetting, .defaultValue = 170, .limitHandler = IntLimit(64, 256, 170), }}, + { "show_seconds", { + .type = SettingType::BoolSetting, + .defaultValue = false, }}, { "comma_after_mention", { .type = SettingType::BoolSetting, .defaultValue = false, }}, diff --git a/Telegram/SourceFiles/rabbit/settings_menu/rabbit_settings_menu.cpp b/Telegram/SourceFiles/rabbit/settings_menu/rabbit_settings_menu.cpp index 3b066aa587e77..1439d82c05925 100644 --- a/Telegram/SourceFiles/rabbit/settings_menu/rabbit_settings_menu.cpp +++ b/Telegram/SourceFiles/rabbit/settings_menu/rabbit_settings_menu.cpp @@ -249,6 +249,21 @@ namespace Settings { ::RabbitSettings::JsonSettings::GetInt("sticker_height"), updateStickerHeight); updateStickerHeightLabel(::RabbitSettings::JsonSettings::GetInt("sticker_height")); + + AddButtonWithIcon( + container, + rktr("rtg_mute_for_selected_time"), + st::settingsButton, + IconDescriptor{ &st::menuIconReschedule } + )->toggleOn( + rpl::single(::RabbitSettings::JsonSettings::GetBool("show_seconds")) + )->toggledValue( + ) | rpl::filter([](bool enabled) { + return (enabled != ::RabbitSettings::JsonSettings::GetBool("show_seconds")); + }) | rpl::start_with_next([](bool enabled) { + ::RabbitSettings::JsonSettings::Set("show_seconds", enabled); + ::RabbitSettings::JsonSettings::Write(); + }, container->lifetime()); SettingsMenuJsonSwitch(rtg_settings_comma_after_mention, comma_after_mention); }