Skip to content

Commit a07bdf5

Browse files
committed
Limit concurrent notifications
Signed-off-by: Claudio Cambra <claudio.cambra@gmail.com>
1 parent 2ffe640 commit a07bdf5

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

src/gui/tray/usermodel.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,36 @@ void User::slotBuildNotificationDisplay(const ActivityList &list)
116116
{
117117
_activityModel->clearNotifications();
118118

119-
foreach (auto activity, list) {
119+
const auto multipleAccounts = AccountManager::instance()->accounts().count() > 1;
120+
ActivityList toNotifyList;
121+
122+
std::copy_if(list.constBegin(), list.constEnd(), std::back_inserter(toNotifyList), [&](const Activity &activity) {
123+
120124
if (_blacklistedNotifications.contains(activity)) {
121125
qCInfo(lcActivity) << "Activity in blacklist, skip";
122-
continue;
126+
return false;
127+
} else if(_notifiedNotifications.contains(activity._id)) {
128+
qCInfo(lcActivity) << "Activity already notified, skip";
129+
return false;
123130
}
131+
132+
return true;
133+
});
134+
135+
if(toNotifyList.count() > 2) {
136+
const auto subject = QStringLiteral("%1 notifications").arg(toNotifyList.count());
137+
const auto message = multipleAccounts ? toNotifyList.constFirst()._accName : QString();
138+
showDesktopNotification(subject, message, -static_cast<int>(qHash(subject)));
139+
140+
// Set these activities as notified here, rather than in showDesktopNotification
141+
for(const auto &activity : toNotifyList) {
142+
_notifiedNotifications.insert(activity._id);
143+
}
144+
145+
return;
146+
}
147+
148+
for(const auto &activity : toNotifyList) {
124149
const auto message = activity._objectType == QStringLiteral("chat")
125150
? activity._message : AccountManager::instance()->accounts().count() == 1 ? "" : activity._accName;
126151
showDesktopNotification(activity._subject, message, activity._id); // We assigned the notif. id to the activity id

0 commit comments

Comments
 (0)