aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/database
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2024-04-13 07:25:54 -0700
committerAnton Tananaev <anton@traccar.org>2024-04-13 07:25:54 -0700
commit725d738de64bd7df7ec05786baf6590c15a105b9 (patch)
tree060137afc6b1b1a50e1663b1a336734aaf1985b7 /src/main/java/org/traccar/database
parent22228ea159618627c0b6d79c1ad7e87eadbeb598 (diff)
downloadtrackermap-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/database')
-rw-r--r--src/main/java/org/traccar/database/NotificationManager.java13
1 files changed, 13 insertions, 0 deletions
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);