aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2024-04-09 21:24:07 +0300
committerGravatar Vitaly Takmazov2024-04-09 21:24:07 +0300
commit0883630ad9e159a4499ac6bfbef711a7c755582b (patch)
tree2a0425c78a951446cec3d9dfebc5e1e6c0cc119b /src/main/java/com
parent122b1693afbf5ecb1e8f1b9d9414be96960ed210 (diff)
durov: handle reply urls
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/juick/TelegramBotManager.java24
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();