From 93563358ca12055060032b5a0817d886ea4f8416 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 30 Mar 2022 22:57:36 +0300 Subject: [PATCH] Added remain time to notification menu item when peer is muted. --- Telegram/SourceFiles/ui/text/format_values.cpp | 14 ++++++++++++++ Telegram/SourceFiles/ui/text/format_values.h | 1 + Telegram/SourceFiles/window/window_peer_menu.cpp | 8 +++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/ui/text/format_values.cpp b/Telegram/SourceFiles/ui/text/format_values.cpp index 01199b2482..9930cfdeb4 100644 --- a/Telegram/SourceFiles/ui/text/format_values.cpp +++ b/Telegram/SourceFiles/ui/text/format_values.cpp @@ -396,4 +396,18 @@ QString FormatTTLTiny(float64 ttl) { : tr::lng_years_tiny({}, lt_count, std::ceil(ttl / (86400 * 360))); } +QString FormatMuteForTiny(float64 sec) { + return (sec <= 60) + ? QString() + : (sec <= 60 * 59) + ? tr::lng_minutes_tiny(tr::now, lt_count, std::ceil(sec / 60)) + : (sec <= 3600 * 23) + ? tr::lng_hours_tiny(tr::now, lt_count, std::ceil(sec / 3600)) + : (sec <= 86400 * 6) + ? tr::lng_days_tiny(tr::now, lt_count, std::ceil(sec / 86400)) + : (sec <= (86400 * 7) * 3) + ? tr::lng_weeks_tiny(tr::now, lt_count, std::ceil(sec / (86400 * 7))) + : QString(); +} + } // namespace Ui diff --git a/Telegram/SourceFiles/ui/text/format_values.h b/Telegram/SourceFiles/ui/text/format_values.h index 6f33b9f8bd..713d7e948d 100644 --- a/Telegram/SourceFiles/ui/text/format_values.h +++ b/Telegram/SourceFiles/ui/text/format_values.h @@ -28,6 +28,7 @@ inline constexpr auto FileStatusSizeFailed = 0x7FFFFFF2; [[nodiscard]] QString FormatImageSizeText(const QSize &size); [[nodiscard]] QString FormatPhone(const QString &phone); [[nodiscard]] QString FormatTTLTiny(float64 ttl); +[[nodiscard]] QString FormatMuteForTiny(float64 sec); struct CurrencyRule { const char *international = ""; diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 7dccca6f49..5f12f764e8 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "ui/boxes/confirm_box.h" #include "base/options.h" +#include "base/unixtime.h" #include "boxes/delete_messages_box.h" #include "boxes/max_invite_box.h" #include "boxes/mute_settings_box.h" @@ -22,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/peers/edit_contact_box.h" #include "ui/boxes/report_box.h" #include "ui/toast/toast.h" +#include "ui/text/format_values.h" #include "ui/text/text_utilities.h" #include "ui/widgets/labels.h" #include "ui/widgets/checkbox.h" @@ -131,7 +133,11 @@ void PeerMenuAddMuteSubmenuAction( peer->owner().requestNotifySettings(peer); const auto isMuted = peer->owner().notifyIsMuted(peer); if (isMuted) { - addAction(tr::lng_mute_menu_unmute(tr::now), [=] { + const auto text = tr::lng_mute_menu_unmute(tr::now) + + '\t' + + Ui::FormatMuteForTiny(peer->notifyMuteUntil().value_or(0) + - base::unixtime::now()); + addAction(text, [=] { peer->owner().updateNotifySettings(peer, 0); }, &st::menuIconUnmute); } else {