diff options
author | Claudio Cambra <claudio.cambra@gmail.com> | 2022-07-06 17:22:23 +0300 |
---|---|---|
committer | Camila <hello@camila.codes> | 2022-07-12 21:24:50 +0300 |
commit | 7d087026ca902b359ca52d7d9bf05f4b358b3bd9 (patch) | |
tree | bde2ce780f1849a0a049997c8fd5ab40d1db9156 /src/gui/tray | |
parent | b707aef3a25a5f93394849e938af51361bc91908 (diff) |
Limit concurrent notifications
Signed-off-by: Claudio Cambra <claudio.cambra@gmail.com>
Diffstat (limited to 'src/gui/tray')
-rw-r--r-- | src/gui/tray/usermodel.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/gui/tray/usermodel.cpp b/src/gui/tray/usermodel.cpp index 081ccb452..782de47a1 100644 --- a/src/gui/tray/usermodel.cpp +++ b/src/gui/tray/usermodel.cpp @@ -116,11 +116,36 @@ void User::slotBuildNotificationDisplay(const ActivityList &list) { _activityModel->clearNotifications(); - foreach (auto activity, list) { + const auto multipleAccounts = AccountManager::instance()->accounts().count() > 1; + ActivityList toNotifyList; + + std::copy_if(list.constBegin(), list.constEnd(), std::back_inserter(toNotifyList), [&](const Activity &activity) { + if (_blacklistedNotifications.contains(activity)) { qCInfo(lcActivity) << "Activity in blacklist, skip"; - continue; + return false; + } else if(_notifiedNotifications.contains(activity._id)) { + qCInfo(lcActivity) << "Activity already notified, skip"; + return false; } + + return true; + }); + + if(toNotifyList.count() > 2) { + const auto subject = QStringLiteral("%1 notifications").arg(toNotifyList.count()); + const auto message = multipleAccounts ? toNotifyList.constFirst()._accName : QString(); + showDesktopNotification(subject, message, -static_cast<int>(qHash(subject))); + + // Set these activities as notified here, rather than in showDesktopNotification + for(const auto &activity : toNotifyList) { + _notifiedNotifications.insert(activity._id); + } + + return; + } + + for(const auto &activity : toNotifyList) { const auto message = activity._objectType == QStringLiteral("chat") ? activity._message : AccountManager::instance()->accounts().count() == 1 ? "" : activity._accName; showDesktopNotification(activity._subject, message, activity._id); // We assigned the notif. id to the activity id |