diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/juick/TelegramBotManager.java | 24 |
1 files changed, 18 insertions, 6 deletions
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 <a href="%s">log into website</a> 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(); |