Added remain time to notification menu item when peer is muted.

This commit is contained in:
23rd 2022-03-30 22:57:36 +03:00 committed by John Preston
parent d7bf9e285c
commit 93563358ca
3 changed files with 22 additions and 1 deletions

View file

@ -396,4 +396,18 @@ QString FormatTTLTiny(float64 ttl) {
: tr::lng_years_tiny({}, lt_count, std::ceil(ttl / (86400 * 360))); : 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 } // namespace Ui

View file

@ -28,6 +28,7 @@ inline constexpr auto FileStatusSizeFailed = 0x7FFFFFF2;
[[nodiscard]] QString FormatImageSizeText(const QSize &size); [[nodiscard]] QString FormatImageSizeText(const QSize &size);
[[nodiscard]] QString FormatPhone(const QString &phone); [[nodiscard]] QString FormatPhone(const QString &phone);
[[nodiscard]] QString FormatTTLTiny(float64 ttl); [[nodiscard]] QString FormatTTLTiny(float64 ttl);
[[nodiscard]] QString FormatMuteForTiny(float64 sec);
struct CurrencyRule { struct CurrencyRule {
const char *international = ""; const char *international = "";

View file

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "ui/boxes/confirm_box.h" #include "ui/boxes/confirm_box.h"
#include "base/options.h" #include "base/options.h"
#include "base/unixtime.h"
#include "boxes/delete_messages_box.h" #include "boxes/delete_messages_box.h"
#include "boxes/max_invite_box.h" #include "boxes/max_invite_box.h"
#include "boxes/mute_settings_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 "boxes/peers/edit_contact_box.h"
#include "ui/boxes/report_box.h" #include "ui/boxes/report_box.h"
#include "ui/toast/toast.h" #include "ui/toast/toast.h"
#include "ui/text/format_values.h"
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "ui/widgets/labels.h" #include "ui/widgets/labels.h"
#include "ui/widgets/checkbox.h" #include "ui/widgets/checkbox.h"
@ -131,7 +133,11 @@ void PeerMenuAddMuteSubmenuAction(
peer->owner().requestNotifySettings(peer); peer->owner().requestNotifySettings(peer);
const auto isMuted = peer->owner().notifyIsMuted(peer); const auto isMuted = peer->owner().notifyIsMuted(peer);
if (isMuted) { 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); peer->owner().updateNotifySettings(peer, 0);
}, &st::menuIconUnmute); }, &st::menuIconUnmute);
} else { } else {