Skip to content

Commit

Permalink
added a 'auto-hide' notifications setting
Browse files Browse the repository at this point in the history
  • Loading branch information
levnikmyskin committed Jan 3, 2021
1 parent 373635a commit b74b3b1
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions Telegram/Resources/langs/lang.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
10 changes: 9 additions & 1 deletion Telegram/SourceFiles/core/core_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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()"));
Expand All @@ -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<DBINotifyView>(notifyView);
switch (uncheckedNotifyView) {
case dbinvShowNothing:
Expand Down Expand Up @@ -459,6 +466,7 @@ void Settings::resetOnLastLogout() {
_soundNotify = true;
_desktopNotify = true;
_flashBounceNotify = true;
_autoHideNotifications = false;
_notifyView = dbinvShowPreview;
//_nativeNotifications = false;
//_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 @@ -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;
}
Expand Down Expand Up @@ -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;
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 @@ -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);
Expand Down Expand Up @@ -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());
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 @@ -44,6 +44,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 @@ -40,6 +40,8 @@ namespace Notifications {
namespace Default {
namespace {

constexpr auto autoHideInterval = 2000;

int notificationMaxHeight() {
return st::notifyMinHeight + st::notifyReplyArea.heightMax + st::notifyBorderWidth;
}
Expand Down Expand Up @@ -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 > autoHideInterval) && !hasReplyingNotifications) {
startHiding();
_waitingForInput = false;
return true;
}
}

const auto waitForUserInput = base::Platform::LastUserInputTimeSupported()
? (Core::App().lastNonIdleTime() <= _started)
Expand Down

0 comments on commit b74b3b1

Please sign in to comment.