From 725d738de64bd7df7ec05786baf6590c15a105b9 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 13 Apr 2024 07:25:54 -0700 Subject: Option to block notifications for users --- src/main/java/org/traccar/database/NotificationManager.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/main/java/org/traccar/database') diff --git a/src/main/java/org/traccar/database/NotificationManager.java b/src/main/java/org/traccar/database/NotificationManager.java index 65437f0a1..60b4f246b 100644 --- a/src/main/java/org/traccar/database/NotificationManager.java +++ b/src/main/java/org/traccar/database/NotificationManager.java @@ -42,8 +42,10 @@ import jakarta.annotation.Nullable; import jakarta.inject.Inject; import jakarta.inject.Singleton; import java.util.Arrays; +import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import java.util.stream.Collectors; @Singleton @@ -59,6 +61,7 @@ public class NotificationManager { private final boolean geocodeOnRequest; private final long timeThreshold; + private final Set blockedUsers = new HashSet<>(); @Inject public NotificationManager( @@ -71,6 +74,12 @@ public class NotificationManager { this.geocoder = geocoder; geocodeOnRequest = config.getBoolean(Keys.GEOCODER_ON_REQUEST); timeThreshold = config.getLong(Keys.NOTIFICATOR_TIME_THRESHOLD); + String blockedUsersString = config.getString(Keys.NOTIFICATION_BLOCK_USERS); + if (blockedUsersString != null) { + for (String userIdString : blockedUsersString.split(",")) { + blockedUsers.add(Long.parseLong(userIdString)); + } + } } private void updateEvent(Event event, Position position) { @@ -122,6 +131,10 @@ public class NotificationManager { notifications.forEach(notification -> { cacheManager.getNotificationUsers(notification.getId(), event.getDeviceId()).forEach(user -> { + if (blockedUsers.contains(user.getId())) { + LOGGER.info("User {} notification blocked", user.getId()); + return; + } for (String notificator : notification.getNotificatorsTypes()) { try { notificatorManager.getNotificator(notificator).send(notification, user, event, position); -- cgit v1.2.3