From ff7104a0c73738815e478a585f2b9ebd0f8aef59 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 | 7 +++++++ 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, 36 insertions(+) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index dcfb9aeadd0d7c..e11e0b49f7a40f 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -327,6 +327,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_events_title" = "Events"; "lng_settings_events_joined" = "Contact joined Telegram"; "lng_settings_events_pinned" = "Pinned messages"; +"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 ca70b71c67cf04..a7e1afd19f49dd 100644 --- a/Telegram/SourceFiles/core/core_settings.cpp +++ b/Telegram/SourceFiles/core/core_settings.cpp @@ -116,6 +116,7 @@ QByteArray Settings::serialize() const { << _groupCallPushToTalkShortcut << qint64(_groupCallPushToTalkDelay) << qint32(_callAudioBackend); + << qint32(_autoHideNotifications ? 1 : 0); } return result; } @@ -187,6 +188,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { QByteArray groupCallPushToTalkShortcut = _groupCallPushToTalkShortcut; qint64 groupCallPushToTalkDelay = _groupCallPushToTalkDelay; qint32 callAudioBackend = static_cast(_callAudioBackend); + qint32 autoHideNotifications = _autoHideNotifications ? 1 : 0; stream >> themesAccentColors; if (!stream.atEnd()) { @@ -284,6 +286,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) { } if (!stream.atEnd()) { stream >> callAudioBackend; + } + if (!stream.atEnd()) { + stream >> autoHideNotifications; } if (stream.status() != QDataStream::Ok) { LOG(("App Error: " @@ -303,6 +308,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: @@ -475,6 +481,7 @@ void Settings::resetOnLastLogout() { _soundNotify = true; _desktopNotify = true; _flashBounceNotify = true; + _autoHideNotifications = false; _notifyView = dbinvShowPreview; //_nativeNotifications = false; //_notificationsCount = 3; diff --git a/Telegram/SourceFiles/core/core_settings.h b/Telegram/SourceFiles/core/core_settings.h index a476dde4b1a6ad..50d3094403b53e 100644 --- a/Telegram/SourceFiles/core/core_settings.h +++ b/Telegram/SourceFiles/core/core_settings.h @@ -128,6 +128,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; } @@ -527,6 +533,7 @@ class Settings final { bool _soundNotify = true; bool _desktopNotify = true; bool _flashBounceNotify = true; + bool _autoHideNotifications = false; DBINotifyView _notifyView = dbinvShowPreview; bool _nativeNotifications = false; int _notificationsCount = 3; diff --git a/Telegram/SourceFiles/settings/settings_notifications.cpp b/Telegram/SourceFiles/settings/settings_notifications.cpp index f6ce983b0b472e..a8c42c88b94ec3 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); @@ -780,6 +783,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 5e21ae30d0280f..e0447387acae66 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 b923e5d3affb72..54f9da6d0b14ba 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)