aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2024-01-15 15:49:36 -0800
committerAnton Tananaev <anton@traccar.org>2024-01-15 15:49:36 -0800
commita531585474ca9ee7437d2a5b1698d1cf5f507a09 (patch)
tree8cb92b92c8d2970cd1c8375fae1e69abc97f21b0 /src
parent2b893df60f62ee8b363cd6dd528c155bb5124c5c (diff)
downloadtrackermap-server-a531585474ca9ee7437d2a5b1698d1cf5f507a09.tar.gz
trackermap-server-a531585474ca9ee7437d2a5b1698d1cf5f507a09.tar.bz2
trackermap-server-a531585474ca9ee7437d2a5b1698d1cf5f507a09.zip
Add notification to templates
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/notification/NotificationFormatter.java5
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorFirebase.java2
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorMail.java2
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorPushover.java2
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorSms.java2
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorTelegram.java2
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorTraccar.java2
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorWeb.java2
8 files changed, 11 insertions, 8 deletions
diff --git a/src/main/java/org/traccar/notification/NotificationFormatter.java b/src/main/java/org/traccar/notification/NotificationFormatter.java
index e994729c0..7685eac0d 100644
--- a/src/main/java/org/traccar/notification/NotificationFormatter.java
+++ b/src/main/java/org/traccar/notification/NotificationFormatter.java
@@ -23,6 +23,7 @@ import org.traccar.model.Driver;
import org.traccar.model.Event;
import org.traccar.model.Geofence;
import org.traccar.model.Maintenance;
+import org.traccar.model.Notification;
import org.traccar.model.Position;
import org.traccar.model.Server;
import org.traccar.model.User;
@@ -44,13 +45,15 @@ public class NotificationFormatter {
this.textTemplateFormatter = textTemplateFormatter;
}
- public NotificationMessage formatMessage(User user, Event event, Position position, String templatePath) {
+ public NotificationMessage formatMessage(
+ Notification notification, User user, Event event, Position position, String templatePath) {
Server server = cacheManager.getServer();
Device device = cacheManager.getObject(Device.class, event.getDeviceId());
VelocityContext velocityContext = textTemplateFormatter.prepareContext(server, user);
+ velocityContext.put("notification", notification);
velocityContext.put("device", device);
velocityContext.put("event", event);
if (position != null) {
diff --git a/src/main/java/org/traccar/notificators/NotificatorFirebase.java b/src/main/java/org/traccar/notificators/NotificatorFirebase.java
index d75eb21a9..89031ba26 100644
--- a/src/main/java/org/traccar/notificators/NotificatorFirebase.java
+++ b/src/main/java/org/traccar/notificators/NotificatorFirebase.java
@@ -85,7 +85,7 @@ public class NotificatorFirebase implements Notificator {
public void send(Notification notification, User user, Event event, Position position) throws MessageException {
if (user.hasAttribute("notificationTokens")) {
- var shortMessage = notificationFormatter.formatMessage(user, event, position, "short");
+ var shortMessage = notificationFormatter.formatMessage(notification, user, event, position, "short");
List<String> registrationTokens = new ArrayList<>(
Arrays.asList(user.getString("notificationTokens").split("[, ]")));
diff --git a/src/main/java/org/traccar/notificators/NotificatorMail.java b/src/main/java/org/traccar/notificators/NotificatorMail.java
index 3ab050686..11d4c5bae 100644
--- a/src/main/java/org/traccar/notificators/NotificatorMail.java
+++ b/src/main/java/org/traccar/notificators/NotificatorMail.java
@@ -43,7 +43,7 @@ public class NotificatorMail implements Notificator {
@Override
public void send(Notification notification, User user, Event event, Position position) throws MessageException {
try {
- var fullMessage = notificationFormatter.formatMessage(user, event, position, "full");
+ var fullMessage = notificationFormatter.formatMessage(notification, user, event, position, "full");
mailManager.sendMessage(user, false, fullMessage.getSubject(), fullMessage.getBody());
} catch (MessagingException e) {
throw new MessageException(e);
diff --git a/src/main/java/org/traccar/notificators/NotificatorPushover.java b/src/main/java/org/traccar/notificators/NotificatorPushover.java
index 9f2a8c94d..cf4c4026b 100644
--- a/src/main/java/org/traccar/notificators/NotificatorPushover.java
+++ b/src/main/java/org/traccar/notificators/NotificatorPushover.java
@@ -63,7 +63,7 @@ public class NotificatorPushover implements Notificator {
@Override
public void send(Notification notification, User user, Event event, Position position) {
- var shortMessage = notificationFormatter.formatMessage(user, event, position, "short");
+ var shortMessage = notificationFormatter.formatMessage(notification, user, event, position, "short");
Message message = new Message();
message.token = token;
diff --git a/src/main/java/org/traccar/notificators/NotificatorSms.java b/src/main/java/org/traccar/notificators/NotificatorSms.java
index 2b6b20b1b..ce362290e 100644
--- a/src/main/java/org/traccar/notificators/NotificatorSms.java
+++ b/src/main/java/org/traccar/notificators/NotificatorSms.java
@@ -46,7 +46,7 @@ public class NotificatorSms implements Notificator {
@Override
public void send(Notification notification, User user, Event event, Position position) throws MessageException {
if (user.getPhone() != null) {
- var shortMessage = notificationFormatter.formatMessage(user, event, position, "short");
+ var shortMessage = notificationFormatter.formatMessage(notification, user, event, position, "short");
statisticsManager.registerSms();
smsManager.sendMessage(user.getPhone(), shortMessage.getBody(), false);
}
diff --git a/src/main/java/org/traccar/notificators/NotificatorTelegram.java b/src/main/java/org/traccar/notificators/NotificatorTelegram.java
index c91aaa4ff..eaee32810 100644
--- a/src/main/java/org/traccar/notificators/NotificatorTelegram.java
+++ b/src/main/java/org/traccar/notificators/NotificatorTelegram.java
@@ -87,7 +87,7 @@ public class NotificatorTelegram implements Notificator {
@Override
public void send(Notification notification, User user, Event event, Position position) {
- var shortMessage = notificationFormatter.formatMessage(user, event, position, "short");
+ var shortMessage = notificationFormatter.formatMessage(notification, user, event, position, "short");
TextMessage message = new TextMessage();
message.chatId = user.getString("telegramChatId");
diff --git a/src/main/java/org/traccar/notificators/NotificatorTraccar.java b/src/main/java/org/traccar/notificators/NotificatorTraccar.java
index 717742a1e..c00e3e029 100644
--- a/src/main/java/org/traccar/notificators/NotificatorTraccar.java
+++ b/src/main/java/org/traccar/notificators/NotificatorTraccar.java
@@ -87,7 +87,7 @@ public class NotificatorTraccar implements Notificator {
public void send(org.traccar.model.Notification notification, User user, Event event, Position position) {
if (user.hasAttribute("notificationTokens")) {
- var shortMessage = notificationFormatter.formatMessage(user, event, position, "short");
+ var shortMessage = notificationFormatter.formatMessage(notification, user, event, position, "short");
NotificationObject item = new NotificationObject();
item.title = shortMessage.getSubject();
diff --git a/src/main/java/org/traccar/notificators/NotificatorWeb.java b/src/main/java/org/traccar/notificators/NotificatorWeb.java
index 3a125db3c..2b9030226 100644
--- a/src/main/java/org/traccar/notificators/NotificatorWeb.java
+++ b/src/main/java/org/traccar/notificators/NotificatorWeb.java
@@ -51,7 +51,7 @@ public final class NotificatorWeb implements Notificator {
copy.setMaintenanceId(event.getMaintenanceId());
copy.getAttributes().putAll(event.getAttributes());
- var message = notificationFormatter.formatMessage(user, event, position, "short");
+ var message = notificationFormatter.formatMessage(notification, user, event, position, "short");
copy.set("message", message.getBody());
connectionManager.updateEvent(true, user.getId(), copy);