aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorRafaelMiquelino <rafaelmiquelino@gmail.com>2021-06-11 19:14:04 -0300
committerRafaelMiquelino <rafaelmiquelino@gmail.com>2021-06-11 19:14:04 -0300
commitb2f9dc30b30c82202168748cb7350568419b0aca (patch)
tree1162624607d008d2a70c2d2b57c7c9a7afc1c27e /src/main
parent96834fd3ae449d5c47e53b0bcbcd68ec255dfd89 (diff)
downloadtraccar-server-b2f9dc30b30c82202168748cb7350568419b0aca.tar.gz
traccar-server-b2f9dc30b30c82202168748cb7350568419b0aca.tar.bz2
traccar-server-b2f9dc30b30c82202168748cb7350568419b0aca.zip
Modify NotificatorTelegram.java
Add chatId based on "notificationTelegramChatId" user attributes, if available.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorTelegram.java15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/notificators/NotificatorTelegram.java b/src/main/java/org/traccar/notificators/NotificatorTelegram.java
index cd6fb0c45..25dc7567f 100644
--- a/src/main/java/org/traccar/notificators/NotificatorTelegram.java
+++ b/src/main/java/org/traccar/notificators/NotificatorTelegram.java
@@ -1,5 +1,6 @@
/*
* Copyright 2019 - 2021 Anton Tananaev (anton@traccar.org)
+ * Copyright 2021 Rafael Miquelino (rafaelmiquelino@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +20,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.Context;
+import org.traccar.model.User;
import org.traccar.config.Keys;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -81,9 +83,9 @@ public class NotificatorTelegram extends Notificator {
});
}
- private LocationMessage createLocationMessage(Position position) {
+ private LocationMessage createLocationMessage(String messageChatId, Position position) {
LocationMessage locationMessage = new LocationMessage();
- locationMessage.chatId = chatId;
+ locationMessage.chatId = messageChatId;
locationMessage.latitude = position.getLatitude();
locationMessage.longitude = position.getLongitude();
locationMessage.bearing = (int) Math.ceil(position.getCourse());
@@ -93,12 +95,17 @@ public class NotificatorTelegram extends Notificator {
@Override
public void sendSync(long userId, Event event, Position position) {
+ User user = Context.getPermissionsManager().getUser(userId);
TextMessage message = new TextMessage();
- message.chatId = chatId;
+ if (user.getAttributes().containsKey("notificationTelegramChatId")) {
+ message.chatId = user.getString("notificationTelegramChatId");
+ } else {
+ message.chatId = chatId;
+ }
message.text = NotificationFormatter.formatShortMessage(userId, event, position);
executeRequest(urlSendText, message);
if (position != null) {
- executeRequest(urlSendLocation, createLocationMessage(position));
+ executeRequest(urlSendLocation, createLocationMessage(message.chatId, position));
}
}