diff options
author | Anton Tananaev <anton@traccar.org> | 2024-04-13 07:25:54 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2024-04-13 07:25:54 -0700 |
commit | 725d738de64bd7df7ec05786baf6590c15a105b9 (patch) | |
tree | 060137afc6b1b1a50e1663b1a336734aaf1985b7 /src/main/java/org/traccar | |
parent | 22228ea159618627c0b6d79c1ad7e87eadbeb598 (diff) | |
download | trackermap-server-725d738de64bd7df7ec05786baf6590c15a105b9.tar.gz trackermap-server-725d738de64bd7df7ec05786baf6590c15a105b9.tar.bz2 trackermap-server-725d738de64bd7df7ec05786baf6590c15a105b9.zip |
Option to block notifications for users
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r-- | src/main/java/org/traccar/config/Keys.java | 7 | ||||
-rw-r--r-- | src/main/java/org/traccar/database/NotificationManager.java | 13 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index d346084bd..db3c5c9ed 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -1261,6 +1261,13 @@ public final class Keys { List.of(KeyType.CONFIG)); /** + * Block notifications for specific users. The value should be a comma-separated list of internal user ids. + */ + public static final ConfigKey<String> NOTIFICATION_BLOCK_USERS = new StringConfigKey( + "notification.block.users", + List.of(KeyType.CONFIG)); + + /** * Maximum time period for reports in seconds. Can be useful to prevent users to request unreasonably long reports. * By default, there is no limit. */ 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<Long> 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); |