From 613a2f358a77df72ce401e197af5d496207984dc Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 30 Jun 2020 11:52:59 +0400 Subject: [PATCH] Fix clearing session notifications. --- .../linux/notifications_manager_linux.cpp | 34 +++++++++++++------ .../win/notifications_manager_win.cpp | 26 +++++++++----- .../window/notifications_manager.cpp | 14 ++++---- 3 files changed, 47 insertions(+), 27 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp index cf12821ce5..62463eb7ad 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp @@ -582,7 +582,9 @@ void Manager::Private::showNotification( const QString &msg, bool hideNameAndPhoto, bool hideReplyButton) { - if (!Supported()) return; + if (!Supported()) { + return; + } const auto key = FullPeer{ .sessionId = peer->session().uniqueId(), @@ -630,7 +632,9 @@ void Manager::Private::showNotification( } void Manager::Private::clearAll() { - if (!Supported()) return; + if (!Supported()) { + return; + } for (const auto &[key, notifications] : base::take(_notifications)) { for (const auto &[msgId, notification] : notifications) { @@ -640,7 +644,9 @@ void Manager::Private::clearAll() { } void Manager::Private::clearFromHistory(not_null history) { - if (!Supported()) return; + if (!Supported()) { + return; + } const auto key = FullPeer{ .sessionId = history->session().uniqueId(), @@ -658,23 +664,29 @@ void Manager::Private::clearFromHistory(not_null history) { } void Manager::Private::clearFromSession(not_null session) { - if (!Supported()) return; + if (!Supported()) { + return; + } const auto sessionId = session->uniqueId(); for (auto i = _notifications.begin(); i != _notifications.end();) { - if (i->first.sessionId == sessionId) { - const auto temp = base::take(i->second); - i = _notifications.erase(i); + if (i->first.sessionId != sessionId) { + ++i; + continue; + } + const auto temp = base::take(i->second); + i = _notifications.erase(i); - for (const auto &[msgId, notification] : temp) { - notification->close(); - } + for (const auto &[msgId, notification] : temp) { + notification->close(); } } } void Manager::Private::clearNotification(NotificationId id) { - if (!Supported()) return; + if (!Supported()) { + return; + } auto i = _notifications.find(id.full); if (i != _notifications.cend()) { diff --git a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp index f5cfdf51d1..5fd6c591f8 100644 --- a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp +++ b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp @@ -415,7 +415,9 @@ Manager::Private::~Private() { } void Manager::Private::clearAll() { - if (!_notifier) return; + if (!_notifier) { + return; + } auto temp = base::take(_notifications); for (const auto &[key, notifications] : base::take(_notifications)) { @@ -426,7 +428,9 @@ void Manager::Private::clearAll() { } void Manager::Private::clearFromHistory(not_null history) { - if (!_notifier) return; + if (!_notifier) { + return; + } auto i = _notifications.find(FullPeer{ .sessionId = history->session().uniqueId(), @@ -443,17 +447,21 @@ void Manager::Private::clearFromHistory(not_null history) { } void Manager::Private::clearFromSession(not_null session) { - if (!_notifier) return; + if (!_notifier) { + return; + } const auto sessionId = session->uniqueId(); for (auto i = _notifications.begin(); i != _notifications.end();) { - if (i->first.sessionId == sessionId) { - const auto temp = base::take(i->second); - _notifications.erase(i); + if (i->first.sessionId != sessionId) { + ++i; + continue; + } + const auto temp = base::take(i->second); + _notifications.erase(i); - for (const auto &[msgId, notification] : temp) { - _notifier->Hide(notification.p.Get()); - } + for (const auto &[msgId, notification] : temp) { + _notifier->Hide(notification.p.Get()); } } } diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index e542e5ee08..9ab2fe0226 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -207,15 +207,15 @@ void System::clearFromSession(not_null session) { for (auto i = _whenMaps.begin(); i != _whenMaps.end();) { const auto history = i->first; - if (&history->session() == session) { - history->clearNotifications(); - i = _whenMaps.erase(i); - _whenAlerts.remove(history); - _waiters.remove(history); - _settingWaiters.remove(history); - } else { + if (&history->session() != session) { ++i; + continue; } + history->clearNotifications(); + i = _whenMaps.erase(i); + _whenAlerts.remove(history); + _waiters.remove(history); + _settingWaiters.remove(history); } const auto clearFrom = [&](auto &map) { for (auto i = map.begin(); i != map.end();) {