From fa89377ea880c2fc6f382ba988675fe159ad85fc Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 4 Dec 2023 03:48:10 +0300 Subject: Use telegram message caption when trying to edit message with image --- src/main/java/com/juick/TelegramBotManager.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/main/java/com/juick') diff --git a/src/main/java/com/juick/TelegramBotManager.java b/src/main/java/com/juick/TelegramBotManager.java index 3335b61a..dec0bd1d 100644 --- a/src/main/java/com/juick/TelegramBotManager.java +++ b/src/main/java/com/juick/TelegramBotManager.java @@ -60,6 +60,7 @@ import java.io.IOException; import java.net.URI; import java.net.URL; import java.util.*; +import java.util.stream.Stream; import static com.juick.util.formatters.PlainTextFormatter.formatPost; import static com.juick.util.formatters.PlainTextFormatter.formatUrl; @@ -147,7 +148,8 @@ public class TelegramBotManager implements NotificationListener { com.juick.model.Message originalMessage = rid == 0 ? messagesService.getMessage(mid).orElseThrow(IllegalStateException::new) : messagesService.getReply(mid, rid); User author = originalMessage.getUser(); - String newMessageText = StringUtils.defaultString(message.text()); + String newMessageText = Stream.of(message.text(), message.caption()).filter(Objects::nonNull) + .findFirst().orElse(StringUtils.EMPTY); if (user_from.equals(author) && canUpdateMessage(originalMessage, newMessageText)) { if (messagesService.updateMessage(mid, rid, newMessageText, false)) { telegramNotify(message.chat().id(), "Message updated", new com.juick.model.Message()); -- cgit v1.2.3