Skip to content

Commit

Permalink
added a 'auto-hide' notifications setting
Browse files Browse the repository at this point in the history
levnikmyskin committed Jan 24, 2021
1 parent 9b9531d commit ff7104a
Showing 6 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions Telegram/Resources/langs/lang.strings
Original file line number Diff line number Diff line change
@@ -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";
7 changes: 7 additions & 0 deletions Telegram/SourceFiles/core/core_settings.cpp
Original file line number Diff line number Diff line change
@@ -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<qint32>(_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<DBINotifyView>(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;
7 changes: 7 additions & 0 deletions Telegram/SourceFiles/core/core_settings.h
Original file line number Diff line number Diff line change
@@ -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;
11 changes: 11 additions & 0 deletions Telegram/SourceFiles/settings/settings_notifications.cpp
Original file line number Diff line number Diff line change
@@ -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());
1 change: 1 addition & 0 deletions Telegram/SourceFiles/window/notifications_manager.h
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@ enum class ChangeType {
MaxCount,
Corner,
DemoIsShown,
AutoHideEnabled,
};

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

0 comments on commit ff7104a

Please sign in to comment.