From 9f4b8a0765f83e6d32f1a6f358baacf2bef73c75 Mon Sep 17 00:00:00 2001 From: Jared <7060603@hotmail.ca> Date: Sun, 12 Jan 2025 13:22:41 -0700 Subject: [PATCH] fix(Notify): Ungroup dbus notifications Send a new notification for each event instead of reusing one notification. --- src/model/notificationgenerator.cpp | 117 ++---------------- .../desktopnotifybackend_dbus.cpp | 2 +- 2 files changed, 11 insertions(+), 108 deletions(-) diff --git a/src/model/notificationgenerator.cpp b/src/model/notificationgenerator.cpp index de3c60e670..17a643d492 100644 --- a/src/model/notificationgenerator.cpp +++ b/src/model/notificationgenerator.cpp @@ -10,62 +10,6 @@ #include namespace { -size_t getNumMessages(const QHash& friendNotifications, - const QHash& conferenceNotifications) -{ - auto numMessages = std::accumulate(friendNotifications.begin(), friendNotifications.end(), 0); - numMessages = - std::accumulate(conferenceNotifications.begin(), conferenceNotifications.end(), numMessages); - - return numMessages; -} - -size_t getNumChats(const QHash& friendNotifications, - const QHash& conferenceNotifications) -{ - return friendNotifications.size() + conferenceNotifications.size(); -} - -QString generateMultiChatTitle(size_t numChats, size_t numMessages) -{ - //: e.g. 3 messages from 2 chats - return QObject::tr("%1 message(s) from %2 chats").arg(numMessages).arg(numChats); -} - -template -QString generateSingleChatTitle(const QHash numNotifications, T contact) -{ - if (numNotifications[contact] > 1) { - //: e.g. 2 messages from Bob - return QObject::tr("%1 message(s) from %2") - .arg(numNotifications[contact]) - .arg(contact->getDisplayedName()); - } - return contact->getDisplayedName(); -} - -QString generateTitle(const QHash& friendNotifications, - const QHash& conferenceNotifications, const Friend* f) -{ - auto numChats = getNumChats(friendNotifications, conferenceNotifications); - if (numChats > 1) { - return generateMultiChatTitle(numChats, - getNumMessages(friendNotifications, conferenceNotifications)); - } - return generateSingleChatTitle(friendNotifications, f); -} - -QString generateTitle(const QHash& friendNotifications, - const QHash& conferenceNotifications, - const Conference* c) -{ - auto numChats = getNumChats(friendNotifications, conferenceNotifications); - if (numChats > 1) { - return generateMultiChatTitle(numChats, - getNumMessages(friendNotifications, conferenceNotifications)); - } - return generateSingleChatTitle(conferenceNotifications, c); -} QString generateContent(const QHash& friendNotifications, const QHash& conferenceNotifications, @@ -73,38 +17,6 @@ QString generateContent(const QHash& friendNotifications, { assert(!friendNotifications.empty() || !conferenceNotifications.empty()); - auto numChats = getNumChats(friendNotifications, conferenceNotifications); - if (numChats > 1) { - // Copy all names into a vector to simplify formatting logic between - // multiple lists - std::vector displayNames; - displayNames.reserve(numChats); - - for (auto it = friendNotifications.begin(); it != friendNotifications.end(); ++it) { - displayNames.push_back(it.key()->getDisplayedName()); - } - - for (auto it = conferenceNotifications.begin(); it != conferenceNotifications.end(); ++it) { - displayNames.push_back(it.key()->getDisplayedName()); - } - - assert(!displayNames.empty()); - - // Lexicographically sort all display names to ensure consistent formatting - QCollator collator; - std::sort(displayNames.begin(), displayNames.end(), - [&](const QString& a, const QString& b) { return collator.compare(a, b) < 1; }); - - auto it = displayNames.begin(); - - QString ret = *it; - - while (++it != displayNames.end()) { - ret += ", " + *it; - } - - return ret; - } if (conferenceNotifications.size() == 1) { auto it = conferenceNotifications.begin(); if (it == conferenceNotifications.end()) { @@ -141,9 +53,8 @@ NotificationData NotificationGenerator::friendMessageNotification(const Friend* return ret; } - ret.title = generateTitle(friendNotifications, conferenceNotifications, f); - ret.message = - generateContent(friendNotifications, conferenceNotifications, message, f->getPublicKey()); + ret.title = f->getDisplayedName(); + ret.message = message; ret.category = "im.received"; ret.pixmap = getSenderAvatar(profile, f->getPublicKey()); @@ -158,11 +69,12 @@ NotificationData NotificationGenerator::incomingCallNotification(const Friend* f if (notificationSettings.getNotifyHide()) { ret.title = tr("Incoming call"); + ret.category = "call.incoming"; return ret; } - ret.title = generateTitle(friendNotifications, conferenceNotifications, f); - ret.message = generateContent(friendNotifications, conferenceNotifications, "", f->getPublicKey()); + ret.title = f->getDisplayedName(); + ret.message = tr("Incoming call"); ret.category = "call.incoming"; ret.pixmap = getSenderAvatar(profile, f->getPublicKey()); @@ -182,8 +94,9 @@ NotificationData NotificationGenerator::conferenceMessageNotification(const Conf return ret; } - ret.title = generateTitle(friendNotifications, conferenceNotifications, c); + ret.title = c->getDisplayedName(); ret.message = generateContent(friendNotifications, conferenceNotifications, message, sender); + ret.category = "im.received"; ret.pixmap = getSenderAvatar(profile, sender); return ret; @@ -202,19 +115,9 @@ NotificationData NotificationGenerator::fileTransferNotification(const Friend* f return ret; } - auto numChats = getNumChats(friendNotifications, conferenceNotifications); - auto numMessages = getNumMessages(friendNotifications, conferenceNotifications); - - if (numChats > 1 || numMessages > 1) { - ret.title = generateTitle(friendNotifications, conferenceNotifications, f); - ret.message = generateContent(friendNotifications, conferenceNotifications, - tr("Incoming file transfer"), f->getPublicKey()); - } else { - //: e.g. Bob - file transfer - ret.title = tr("%1 - file transfer").arg(f->getDisplayedName()); - ret.message = filename + " (" + getHumanReadableSize(fileSize) + ")"; - } - + //: e.g. Bob - file transfer + ret.title = tr("%1 - file transfer").arg(f->getDisplayedName()); + ret.message = filename + " (" + getHumanReadableSize(fileSize) + ")"; ret.category = "transfer"; ret.pixmap = getSenderAvatar(profile, f->getPublicKey()); diff --git a/src/platform/desktop_notifications/desktopnotifybackend_dbus.cpp b/src/platform/desktop_notifications/desktopnotifybackend_dbus.cpp index 49db7087e4..8cb8610b26 100644 --- a/src/platform/desktop_notifications/desktopnotifybackend_dbus.cpp +++ b/src/platform/desktop_notifications/desktopnotifybackend_dbus.cpp @@ -342,7 +342,7 @@ bool DesktopNotifyBackend::showMessage(const QString& title, const QString& mess // app_name QApplication::applicationName(), // replaces_id - d->id, + static_cast(0), // app_icon QStringLiteral("dialog-password"), // summary