From 0883630ad9e159a4499ac6bfbef711a7c755582b Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 9 Apr 2024 21:24:07 +0300 Subject: durov: handle reply urls --- src/main/java/com/juick/TelegramBotManager.java | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (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 130934c5..cf38ab5c 100644 --- a/src/main/java/com/juick/TelegramBotManager.java +++ b/src/main/java/com/juick/TelegramBotManager.java @@ -46,6 +46,7 @@ import com.pengrad.telegrambot.request.SetWebhook; import com.pengrad.telegrambot.response.GetFileResponse; import com.pengrad.telegrambot.response.SendResponse; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.tuple.Pair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -204,20 +205,31 @@ public class TelegramBotManager implements NotificationListener { String msg = String.format(""" Hi, %s! You can post messages and images to Juick there. - Tap to [log into website](%s) to get more info""", user_from.getName(), msgUrl); + Tap to log into website to get more info""", user_from.getName(), msgUrl); telegramNotify(message.from().id(), msg, new com.juick.model.Message()); } else { int messageNumber = 0; + int replyNumber = 0; try { - messageNumber = WebUtils.getMessageNumberFromUrl(webDomain, UriComponentsBuilder.fromHttpUrl(text.trim()).build()); + var messageUri = UriComponentsBuilder.fromHttpUrl(text.trim()).build(); + messageNumber = WebUtils.getMessageNumberFromUrl(webDomain, messageUri); + replyNumber = NumberUtils.toInt(messageUri.getFragment(), 0); } catch (IllegalArgumentException ignored) { } if (messageNumber > 0) { - var msg = messagesService.getMessage(messageNumber); - if (msg.isPresent()) { - telegramNotify(message.from().id(), formatTelegramMessage(msg.get()), msg.get()); - return; + if (replyNumber > 0) { + var msg = messagesService.getReply(messageNumber, replyNumber); + if (msg != null) { + telegramNotify(message.from().id(), formatTelegramMessage(msg), msg); + return; + } + } else { + var msg = messagesService.getMessage(messageNumber); + if (msg.isPresent()) { + telegramNotify(message.from().id(), formatTelegramMessage(msg.get()), msg.get()); + return; + } } } Message replyMessage = message.replyToMessage(); -- cgit v1.2.3