diff --git a/libnotificationmanager/server_p.h b/libnotificationmanager/server_p.h --- a/libnotificationmanager/server_p.h +++ b/libnotificationmanager/server_p.h @@ -23,6 +23,8 @@ #include #include +#include "notification.h" + class QDBusServiceWatcher; struct Inhibition @@ -37,8 +39,6 @@ namespace NotificationManager { -class Notification; - class Q_DECL_HIDDEN ServerPrivate : public QObject, protected QDBusContext { Q_OBJECT @@ -97,6 +97,8 @@ QHash m_inhibitions; QHash m_inhibitionServices; + Notification m_lastNotification; + }; } // namespace NotificationManager diff --git a/libnotificationmanager/server_p.cpp b/libnotificationmanager/server_p.cpp --- a/libnotificationmanager/server_p.cpp +++ b/libnotificationmanager/server_p.cpp @@ -186,6 +186,24 @@ } } + // If multiple identical notifications are sent in quick succession, refuse the request + if (m_lastNotification.applicationName() == notification.applicationName() + && m_lastNotification.summary() == notification.summary() + && m_lastNotification.body() == notification.body() + && m_lastNotification.desktopEntry() == notification.desktopEntry() + && m_lastNotification.eventId() == notification.eventId() + && m_lastNotification.actionNames() == notification.actionNames() + && m_lastNotification.urls() == notification.urls() + && m_lastNotification.created().msecsTo(notification.created()) < 1000) { + qCDebug(NOTIFICATIONMANAGER) << "Discarding excess notification creation request"; + + sendErrorReply(QStringLiteral("org.freedesktop.Notifications.Error.ExcessNotificationGeneration"), + QStringLiteral("Created too many similar notifications in quick succession")); + return 0; + } + + m_lastNotification = notification; + if (wasReplaced) { notification.resetUpdated(); emit static_cast(parent())->notificationReplaced(replaces_id, notification);