aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick')
-rw-r--r--src/main/java/com/juick/TelegramBotManager.java9
-rw-r--r--src/main/java/com/juick/util/WebUtils.java13
2 files changed, 22 insertions, 0 deletions
diff --git a/src/main/java/com/juick/TelegramBotManager.java b/src/main/java/com/juick/TelegramBotManager.java
index dec0bd1d..53ef2f47 100644
--- a/src/main/java/com/juick/TelegramBotManager.java
+++ b/src/main/java/com/juick/TelegramBotManager.java
@@ -20,6 +20,7 @@ package com.juick;
import com.juick.model.User;
import com.juick.model.AnonymousUser;
import com.juick.model.CommandResult;
+import com.juick.util.WebUtils;
import com.juick.www.api.SystemActivity;
import com.juick.util.HttpUtils;
import com.juick.service.MessagesService;
@@ -206,6 +207,14 @@ public class TelegramBotManager implements NotificationListener {
Tap to [log into website](%s) to get more info""", user_from.getName(), msgUrl);
telegramNotify(message.from().id(), msg, new com.juick.model.Message());
} else {
+ var messageNumber = WebUtils.getMessageNumberFromUrl(webDomain, UriComponentsBuilder.fromUriString(text.trim()).build());
+ if (messageNumber > 0) {
+ var msg = messagesService.getMessage(messageNumber);
+ if (msg.isPresent()) {
+ telegramNotify(message.from().id(), formatTelegramMessage(msg.get()), msg.get());
+ return;
+ }
+ }
Message replyMessage = message.replyToMessage();
if (replyMessage != null) {
MessageEntity[] entities = replyMessage.entities();
diff --git a/src/main/java/com/juick/util/WebUtils.java b/src/main/java/com/juick/util/WebUtils.java
index a8e690ed..b9f8ca1a 100644
--- a/src/main/java/com/juick/util/WebUtils.java
+++ b/src/main/java/com/juick/util/WebUtils.java
@@ -17,6 +17,9 @@
package com.juick.util;
+import org.apache.commons.lang3.math.NumberUtils;
+import org.springframework.web.util.UriComponents;
+
import java.util.regex.Pattern;
/**
@@ -63,4 +66,14 @@ public class WebUtils {
.replaceAll("\\'", "\\\\'")
.replaceAll("=", "\\\\\\\\=");
}
+
+ public static int getMessageNumberFromUrl(String ourDomain, UriComponents url) {
+ return getMessageNumberFromUrl(ourDomain, url, false);
+ }
+ public static int getMessageNumberFromUrl(String ourDomain, UriComponents url, boolean legacyOnly) {
+ if (url.getPath() == null || url.getHost() == null) return -1;
+ var messageNumberPathSegment = legacyOnly ? url.getPath().substring(1)
+ : url.getPath().substring(url.getPath().lastIndexOf("/") + 1);
+ return url.getHost().equals(ourDomain) ? NumberUtils.toInt(messageNumberPathSegment, -1) : -1;
+ }
}