summary refs log tree commit diff
path: root/src/notifications
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2022-10-13 17:19:54 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2022-10-13 17:55:07 +0200
commit37009906bb3521db3ae77a0bb39a6943b7ccdec0 (patch)
tree612c6360194266ebb83f96016ff37e6626d57ad6 /src/notifications
parentBump mtxclient (diff)
downloadnheko-37009906bb3521db3ae77a0bb39a6943b7ccdec0.tar.xz
Evaluate push rules locally
Diffstat (limited to 'src/notifications')
-rw-r--r--src/notifications/Manager.cpp22
-rw-r--r--src/notifications/Manager.h11
2 files changed, 29 insertions, 4 deletions
diff --git a/src/notifications/Manager.cpp b/src/notifications/Manager.cpp

index 501bfb3f..6033cc6d 100644 --- a/src/notifications/Manager.cpp +++ b/src/notifications/Manager.cpp
@@ -7,6 +7,7 @@ #include "Cache.h" #include "EventAccessors.h" +#include "Logging.h" #include "Utils.h" QString @@ -33,3 +34,24 @@ NotificationsManager::getMessageTemplate(const mtx::responses::Notification &not return QStringLiteral("%1: %2").arg(sender); } } + +void +NotificationsManager::removeNotifications(const QString &roomId, + const std::vector<QString> &eventIds) +{ + std::string room_id = roomId.toStdString(); + + std::uint64_t markerPos = 0; + for (const auto &e : eventIds) { + markerPos = std::max(markerPos, cache::getEventIndex(room_id, e.toStdString()).value_or(0)); + } + + for (const auto &[roomId, eventId] : this->notificationIds) { + if (roomId != roomId) + continue; + auto idx = cache::getEventIndex(room_id, eventId.toStdString()); + if (!idx || markerPos >= idx) { + removeNotification(roomId, eventId); + } + } +} diff --git a/src/notifications/Manager.h b/src/notifications/Manager.h
index f3b1fe30..05f06dcf 100644 --- a/src/notifications/Manager.h +++ b/src/notifications/Manager.h
@@ -36,6 +36,8 @@ public: void postNotification(const mtx::responses::Notification &notification, const QImage &icon); + void removeNotification(const QString &roomId, const QString &eventId); + signals: void notificationClicked(const QString roomId, const QString eventId); void sendNotificationReply(const QString roomId, const QString eventId, const QString body); @@ -46,7 +48,7 @@ signals: const QImage &icon); public slots: - void removeNotification(const QString &roomId, const QString &eventId); + void removeNotifications(const QString &roomId, const std::vector<QString> &eventId); #if defined(NHEKO_DBUS_SYS) public: @@ -62,9 +64,6 @@ private: const QImage &icon); void closeNotification(uint id); - // notification ID to (room ID, event ID) - QMap<uint, roomEventId> notificationIds; - const bool hasMarkup_; const bool hasImages_; #endif @@ -96,6 +95,10 @@ private slots: private: QString getMessageTemplate(const mtx::responses::Notification &notification); + + // notification ID to (room ID, event ID) + // Only populated on Linux atm + QMap<uint, roomEventId> notificationIds; }; #if defined(NHEKO_DBUS_SYS)