增加消息缓存更新机制

This commit is contained in:
iaom 2023-05-30 11:25:05 +08:00
parent a5ac8ceebf
commit c6c8fe0998
2 changed files with 8 additions and 5 deletions

View File

@ -21,7 +21,7 @@
#define UKUI_NOTIFICATION_SERVER_PRIVATE_H
#include <QObject>
#include <QDBusContext>
#include <QVector>
#include <QMap>
class QDBusServiceWatcher;
namespace NotificationServer {
class Notification {
@ -85,7 +85,7 @@ private:
void sendCache();
QDBusServiceWatcher *m_notificationWatchers = nullptr;
uint m_increasedNotificationId = 1;
QVector<Notification> m_notificationsCache;
QMap<uint, Notification> m_notificationsCache;
};

View File

@ -88,7 +88,7 @@ uint ServerPrivate::Notify(const QString &app_name, uint replaces_id, const QStr
notification.m_body = body;
notification.m_actions = actions;
notification.m_hints = newHints;
m_notificationsCache.append(notification);
m_notificationsCache.insert(id, notification);
return id;
}
for(const QString &service : m_notificationWatchers->watchedServices()) {
@ -171,6 +171,9 @@ void ServerPrivate::UnRegisterClient()
void ServerPrivate::CloseNotification(uint id, uint reason)
{
if(m_notificationsCache.contains(id)) {
m_notificationsCache.remove(id);
}
Q_EMIT NotificationClosed(id, reason);
}
@ -182,8 +185,8 @@ void ServerPrivate::InvokeAction(uint id, const QString &action_key)
void ServerPrivate::sendCache()
{
while(!m_notificationsCache.isEmpty()) {
auto notification = m_notificationsCache.takeFirst();
for(const uint &id : m_notificationsCache.keys()) {
auto notification = m_notificationsCache.take(id);
for(const QString &service : m_notificationWatchers->watchedServices()) {
QDBusMessage msg = QDBusMessage::createMethodCall(service,
QStringLiteral("/NotificationClient"),