From 3f46f759c24746ddd2b8cd05cfc6cb99d5f7fd48 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 12 Jul 2022 11:06:22 -0700 Subject: Filter notifications by device access (fix #4888) --- src/main/java/org/traccar/database/NotificationManager.java | 2 +- src/main/java/org/traccar/session/cache/CacheManager.java | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/traccar/database/NotificationManager.java b/src/main/java/org/traccar/database/NotificationManager.java index ecb44b1d4..5be627f2a 100644 --- a/src/main/java/org/traccar/database/NotificationManager.java +++ b/src/main/java/org/traccar/database/NotificationManager.java @@ -98,7 +98,7 @@ public class NotificationManager { } notifications.forEach(notification -> { - cacheManager.getNotificationUsers(notification.getId()).forEach(user -> { + cacheManager.getNotificationUsers(notification.getId(), event.getDeviceId()).forEach(user -> { for (String notificator : notification.getNotificatorsTypes()) { try { notificatorManager.getNotificator(notificator).send(user, event, position); diff --git a/src/main/java/org/traccar/session/cache/CacheManager.java b/src/main/java/org/traccar/session/cache/CacheManager.java index cd71f5f9f..c1697faf9 100644 --- a/src/main/java/org/traccar/session/cache/CacheManager.java +++ b/src/main/java/org/traccar/session/cache/CacheManager.java @@ -123,10 +123,14 @@ public class CacheManager implements BroadcastInterface { } } - public List getNotificationUsers(long notificationId) { + public List getNotificationUsers(long notificationId, long deviceId) { try { lock.readLock().lock(); - return notificationUsers.get(notificationId); + var users = deviceLinks.get(deviceId).get(User.class).stream() + .collect(Collectors.toUnmodifiableSet()); + return notificationUsers.get(notificationId).stream() + .filter(user -> users.contains(user.getId())) + .collect(Collectors.toUnmodifiableList()); } finally { lock.readLock().unlock(); } -- cgit v1.2.3