aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/config/Keys.java7
-rw-r--r--src/main/java/org/traccar/database/NotificationManager.java13
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);