diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 5efaea8d4f5124..07c242cd5c8661 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 cecd332f0c5d83..c79429fbfd87c2 100644 --- a/Telegram/SourceFiles/core/core_settings.cpp +++ b/Telegram/SourceFiles/core/core_settings.cpp @@ -112,7 +112,8 @@ QByteArray Settings::serialize() const { << qint32(_ipRevealWarning ? 1 : 0) << qint32(_groupCallPushToTalk ? 1 : 0) << _groupCallPushToTalkShortcut - << qint64(_groupCallPushToTalkDelay); + << qint64(_groupCallPushToTalkDelay) + << qint32(_autoHideNotifications ? 1 : 0); } return result; } @@ -183,6 +184,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { qint32 groupCallPushToTalk = _groupCallPushToTalk ? 1 : 0; QByteArray groupCallPushToTalkShortcut = _groupCallPushToTalkShortcut; qint64 groupCallPushToTalkDelay = _groupCallPushToTalkDelay; + qint32 autoHideNotifications = _autoHideNotifications ? 1 : 0; stream >> themesAccentColors; if (!stream.atEnd()) { @@ -275,6 +277,10 @@ void Settings::addFromSerialized(const QByteArray &serialized) { >> groupCallPushToTalkShortcut >> groupCallPushToTalkDelay; } + if (!stream.atEnd()) { + stream + >> autoHideNotifications; + } if (stream.status() != QDataStream::Ok) { LOG(("App Error: " "Bad data for Core::Settings::constructFromSerialized()")); @@ -293,6 +299,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: @@ -459,6 +466,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 c6333ba8291bd8..70f036e6d2cd75 100644 --- a/Telegram/SourceFiles/core/core_settings.h +++ b/Telegram/SourceFiles/core/core_settings.h @@ -124,6 +124,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; } @@ -517,6 +523,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 19ce0db2b20f0c..a4e5e30eff1b13 100644 --- a/Telegram/SourceFiles/settings/settings_notifications.cpp +++ b/Telegram/SourceFiles/settings/settings_notifications.cpp @@ -627,6 +627,9 @@ void SetupNotificationsContent( ? tr::lng_settings_alert_mac : tr::lng_settings_alert_linux)(tr::now), settings.flashBounceNotify()); + const auto auto_hiding = addCheckbox( + tr::lng_settings_autohide_notifications(tr::now), + settings.autoHideNotifications()); AddSkip(container, st::settingsCheckboxesSkip); AddDivider(container); @@ -781,6 +784,14 @@ void SetupNotificationsContent( changed(Change::FlashBounceEnabled); }, flashbounce->lifetime()); + auto_hiding->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); + }, auto_hiding->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 13fbb0c440dd77..3bfb8399a1805c 100644 --- a/Telegram/SourceFiles/window/notifications_manager.h +++ b/Telegram/SourceFiles/window/notifications_manager.h @@ -44,6 +44,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 27d534b4f07a12..46c60a47b3fdc7 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -40,6 +40,8 @@ namespace Notifications { namespace Default { namespace { +constexpr auto kAutoHideInterval = crl::time(2000); + int notificationMaxHeight() { return st::notifyMinHeight + st::notifyReplyArea.heightMax + st::notifyBorderWidth; } @@ -662,6 +664,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)