NotificationsManager: Group notifications per room
Instead of issuing a new notification for every message, bundle them by room. It looks like the code was originally designed to do that and somehow we forgot along the way. It also fixes the leaking in m_notifications as we were never cleaning after it.
This commit is contained in:
@@ -55,18 +55,27 @@ void NotificationsManager::postNotification(NeoChatRoom *room,
|
|||||||
const QString &replyEventId,
|
const QString &replyEventId,
|
||||||
bool canReply)
|
bool canReply)
|
||||||
{
|
{
|
||||||
QPixmap img;
|
const QString roomId = room->id();
|
||||||
img.convertFromImage(icon);
|
KNotification *notification = m_notifications.value(roomId);
|
||||||
KNotification *notification = new KNotification("message");
|
if (!notification) {
|
||||||
|
notification = new KNotification("message");
|
||||||
if (sender == room->displayName()) {
|
m_notifications.insert(roomId, notification);
|
||||||
notification->setTitle(sender);
|
connect(notification, &KNotification::closed, this, [this, roomId] {
|
||||||
} else {
|
m_notifications.remove(roomId);
|
||||||
notification->setTitle(i18n("%1 (%2)", sender, room->displayName()));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
notification->setText(text.toHtmlEscaped());
|
QString entry;
|
||||||
notification->setPixmap(img);
|
if (sender == room->displayName()) {
|
||||||
|
notification->setTitle(sender);
|
||||||
|
entry = text.toHtmlEscaped();
|
||||||
|
} else {
|
||||||
|
notification->setTitle(room->displayName());
|
||||||
|
entry = i18n("%1: %2", sender, text.toHtmlEscaped());
|
||||||
|
}
|
||||||
|
|
||||||
|
notification->setText(entry + '\n' + notification->text());
|
||||||
|
notification->setPixmap(QPixmap::fromImage(icon));
|
||||||
|
|
||||||
notification->setDefaultAction(i18n("Open NeoChat in this room"));
|
notification->setDefaultAction(i18n("Open NeoChat in this room"));
|
||||||
connect(notification, &KNotification::defaultActivated, this, [=]() {
|
connect(notification, &KNotification::defaultActivated, this, [=]() {
|
||||||
@@ -96,10 +105,7 @@ void NotificationsManager::postNotification(NeoChatRoom *room,
|
|||||||
}
|
}
|
||||||
|
|
||||||
notification->setHint(QStringLiteral("x-kde-origin-name"), room->localUser()->id());
|
notification->setHint(QStringLiteral("x-kde-origin-name"), room->localUser()->id());
|
||||||
|
|
||||||
notification->sendEvent();
|
notification->sendEvent();
|
||||||
|
|
||||||
m_notifications.insert(room->id(), notification);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationsManager::postInviteNotification(NeoChatRoom *room, const QString &title, const QString &sender, const QImage &icon)
|
void NotificationsManager::postInviteNotification(NeoChatRoom *room, const QString &title, const QString &sender, const QImage &icon)
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
NotificationsManager(QObject *parent = nullptr);
|
NotificationsManager(QObject *parent = nullptr);
|
||||||
|
|
||||||
QMultiMap<QString, KNotification *> m_notifications;
|
QHash<QString, KNotification *> m_notifications;
|
||||||
QHash<QString, QPointer<KNotification>> m_invitations;
|
QHash<QString, QPointer<KNotification>> m_invitations;
|
||||||
|
|
||||||
bool m_globalNotificationsEnabled = false;
|
bool m_globalNotificationsEnabled = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user