From 0cf2f2613678867898104db30d2a88b119959019 Mon Sep 17 00:00:00 2001 From: alessio Date: Thu, 31 Dec 2020 12:07:33 +0100 Subject: [PATCH] added a 'auto-hide' notifications setting --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/core/core_settings.cpp | 9 ++++++++- Telegram/SourceFiles/core/core_settings.h | 7 +++++++ .../SourceFiles/settings/settings_notifications.cpp | 11 +++++++++++ Telegram/SourceFiles/window/notifications_manager.h | 1 + .../window/notifications_manager_default.cpp | 9 +++++++++ 6 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index eb1d8f8463ed9..17fa0dcbfbde9 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -329,6 +329,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_events_joined" = "Contact joined Telegram"; "lng_settings_events_pinned" = "Pinned messages"; "lng_settings_notifications_calls_title" = "Calls"; +"lng_settings_autohide_notifications" = "Hide after a few seconds"; "lng_notification_preview" = "You have a new message"; "lng_notification_reply" = "Reply"; diff --git a/Telegram/SourceFiles/core/core_settings.cpp b/Telegram/SourceFiles/core/core_settings.cpp index ace2fcd299891..aa63611576e8e 100644 --- a/Telegram/SourceFiles/core/core_settings.cpp +++ b/Telegram/SourceFiles/core/core_settings.cpp @@ -115,7 +115,8 @@ QByteArray Settings::serialize() const { << _groupCallPushToTalkShortcut << qint64(_groupCallPushToTalkDelay) << qint32(0) // Call audio backend - << qint32(_disableCalls ? 1 : 0); + << qint32(_disableCalls ? 1 : 0) + << qint32(_autoHideNotifications ? 1 : 0); } return result; } @@ -188,6 +189,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { qint64 groupCallPushToTalkDelay = _groupCallPushToTalkDelay; qint32 callAudioBackend = 0; qint32 disableCalls = _disableCalls ? 1 : 0; + qint32 autoHideNotifications = _autoHideNotifications ? 1 : 0; stream >> themesAccentColors; if (!stream.atEnd()) { @@ -288,6 +290,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) { } if (!stream.atEnd()) { stream >> disableCalls; + } + if (!stream.atEnd()) { + stream >> autoHideNotifications; } if (stream.status() != QDataStream::Ok) { LOG(("App Error: " @@ -307,6 +312,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { _soundNotify = (soundNotify == 1); _desktopNotify = (desktopNotify == 1); _flashBounceNotify = (flashBounceNotify == 1); + _autoHideNotifications = (autoHideNotifications == 1); const auto uncheckedNotifyView = static_cast(notifyView); switch (uncheckedNotifyView) { case dbinvShowNothing: @@ -483,6 +489,7 @@ void Settings::resetOnLastLogout() { _soundNotify = true; _desktopNotify = true; _flashBounceNotify = true; + _autoHideNotifications = false; _notifyView = dbinvShowPreview; //_nativeNotifications = std::nullopt; //_notificationsCount = 3; diff --git a/Telegram/SourceFiles/core/core_settings.h b/Telegram/SourceFiles/core/core_settings.h index 67ffc1f25710b..2ca48ad65f10d 100644 --- a/Telegram/SourceFiles/core/core_settings.h +++ b/Telegram/SourceFiles/core/core_settings.h @@ -129,6 +129,12 @@ class Settings final { void setFlashBounceNotify(bool value) { _flashBounceNotify = value; } + [[nodiscard]] bool autoHideNotifications() const { + return _autoHideNotifications; + } + void setAutoHideNotifications(bool value) { + _autoHideNotifications = value; + } [[nodiscard]] DBINotifyView notifyView() const { return _notifyView; } @@ -531,6 +537,7 @@ class Settings final { bool _soundNotify = true; bool _desktopNotify = true; bool _flashBounceNotify = true; + bool _autoHideNotifications = false; DBINotifyView _notifyView = dbinvShowPreview; std::optional _nativeNotifications; int _notificationsCount = 3; diff --git a/Telegram/SourceFiles/settings/settings_notifications.cpp b/Telegram/SourceFiles/settings/settings_notifications.cpp index ac51e033c7798..7d3b868f8d766 100644 --- a/Telegram/SourceFiles/settings/settings_notifications.cpp +++ b/Telegram/SourceFiles/settings/settings_notifications.cpp @@ -628,6 +628,9 @@ void SetupNotificationsContent( ? tr::lng_settings_alert_mac : tr::lng_settings_alert_linux)(tr::now), settings.flashBounceNotify()); + const auto autoHiding = addCheckbox( + tr::lng_settings_autohide_notifications(tr::now), + settings.autoHideNotifications()); AddSkip(container, st::settingsCheckboxesSkip); AddDivider(container); @@ -797,6 +800,14 @@ void SetupNotificationsContent( changed(Change::FlashBounceEnabled); }, flashbounce->lifetime()); + autoHiding->checkedChanges( + ) | rpl::filter([](bool checked) { + return (checked != Core::App().settings().autoHideNotifications()); + }) | rpl::start_with_next([=](bool checked) { + Core::App().settings().setAutoHideNotifications(checked); + changed(Change::AutoHideEnabled); + }, autoHiding->lifetime()); + muted->checkedChanges( ) | rpl::filter([=](bool checked) { return (checked != Core::App().settings().includeMutedCounter()); diff --git a/Telegram/SourceFiles/window/notifications_manager.h b/Telegram/SourceFiles/window/notifications_manager.h index 5e21ae30d0280..e0447387acae6 100644 --- a/Telegram/SourceFiles/window/notifications_manager.h +++ b/Telegram/SourceFiles/window/notifications_manager.h @@ -50,6 +50,7 @@ enum class ChangeType { MaxCount, Corner, DemoIsShown, + AutoHideEnabled, }; } // namespace Notifications diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index b923e5d3affb7..54f9da6d0b14b 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -41,6 +41,8 @@ namespace Notifications { namespace Default { namespace { +constexpr auto kAutoHideInterval = crl::time(2000); + int notificationMaxHeight() { return st::notifyMinHeight + st::notifyReplyArea.heightMax + st::notifyBorderWidth; } @@ -663,6 +665,13 @@ void Notification::prepareActionsCache() { bool Notification::checkLastInput(bool hasReplyingNotifications) { if (!_waitingForInput) return true; + if (Core::App().settings().autoHideNotifications()) { + if ((crl::now() - _started > kAutoHideInterval) && !hasReplyingNotifications) { + startHiding(); + _waitingForInput = false; + return true; + } + } const auto waitForUserInput = base::Platform::LastUserInputTimeSupported() ? (Core::App().lastNonIdleTime() <= _started)