diff --git a/src/main/java/com/patbaumgartner/lovebox/telegram/sender/telegram/LoveboxBot.java b/src/main/java/com/patbaumgartner/lovebox/telegram/sender/telegram/LoveboxBot.java index 3eba0b3..bf4d86c 100644 --- a/src/main/java/com/patbaumgartner/lovebox/telegram/sender/telegram/LoveboxBot.java +++ b/src/main/java/com/patbaumgartner/lovebox/telegram/sender/telegram/LoveboxBot.java @@ -10,6 +10,8 @@ import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -40,7 +42,7 @@ public class LoveboxBot extends TelegramLongPollingBot { private final Set chatIds = new TreeSet<>(); private final ConcurrentHashMap loveboxMessageStore = new ConcurrentHashMap<>(); - private final ConcurrentHashMap telegramMessageStore = new ConcurrentHashMap<>(); + private final ConcurrentHashMap>> telegramMessageStore = new ConcurrentHashMap<>(); @Scheduled(fixedRate = 10_000) public void readMessageBox() { @@ -48,9 +50,12 @@ public void readMessageBox() { messages.forEach(p -> { loveboxMessageStore.computeIfPresent(p.left(), (key, value) -> { if (!value.equals(p.right())) { - Message message = telegramMessageStore.get(p.left()); - if (message != null) { - updatePhotoMessageCaption(message, p.right()); + Collection> pairs = telegramMessageStore.get(p.left()); + for (Pair pair : pairs) { + Message message = pair.right(); + if (message != null) { + updatePhotoMessageCaption(message, p.right()); + } } } return value; @@ -109,7 +114,8 @@ public void onUpdateReceived(Update update) { // Send/respond Message for (long chatId : chatIds) { Message sentMessage = sendPhotoMessage(chatId, text, imagePair, statusTripple); - telegramMessageStore.putIfAbsent(statusTripple.left(), sentMessage); + telegramMessageStore.compute(statusTripple.left(), (key, value) -> (value == null) ? new ArrayList<>() : value) + .add(new Pair<>(chatId, sentMessage)); } } }