Skip to content

Commit

Permalink
Merge pull request #4706 from nextcloud/bugfix/limit-concurrent-notif…
Browse files Browse the repository at this point in the history
…ications

Limit concurrent notifications
  • Loading branch information
claucambra authored Jul 12, 2022
2 parents ea0ab54 + bc01db7 commit 15b7ee4
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/gui/tray/usermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 15b7ee4

Please sign in to comment.