Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a 'auto-hide' notifications setting #10043

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Telegram/Resources/langs/lang.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
9 changes: 8 additions & 1 deletion Telegram/SourceFiles/core/core_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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: "
Expand All @@ -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<DBINotifyView>(notifyView);
switch (uncheckedNotifyView) {
case dbinvShowNothing:
Expand Down Expand Up @@ -483,6 +489,7 @@ void Settings::resetOnLastLogout() {
_soundNotify = true;
_desktopNotify = true;
_flashBounceNotify = true;
_autoHideNotifications = false;
_notifyView = dbinvShowPreview;
//_nativeNotifications = std::nullopt;
//_notificationsCount = 3;
Expand Down
7 changes: 7 additions & 0 deletions Telegram/SourceFiles/core/core_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -531,6 +537,7 @@ class Settings final {
bool _soundNotify = true;
bool _desktopNotify = true;
bool _flashBounceNotify = true;
bool _autoHideNotifications = false;
DBINotifyView _notifyView = dbinvShowPreview;
std::optional<bool> _nativeNotifications;
int _notificationsCount = 3;
Expand Down
11 changes: 11 additions & 0 deletions Telegram/SourceFiles/settings/settings_notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/window/notifications_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ enum class ChangeType {
MaxCount,
Corner,
DemoIsShown,
AutoHideEnabled,
};

} // namespace Notifications
Expand Down
9 changes: 9 additions & 0 deletions Telegram/SourceFiles/window/notifications_manager_default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down