aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/api/TelegramBotHook.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/api/TelegramBotHook.java')
-rw-r--r--src/main/java/com/juick/api/TelegramBotHook.java26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/main/java/com/juick/api/TelegramBotHook.java b/src/main/java/com/juick/api/TelegramBotHook.java
index 9a743bc1..a9a35683 100644
--- a/src/main/java/com/juick/api/TelegramBotHook.java
+++ b/src/main/java/com/juick/api/TelegramBotHook.java
@@ -2,6 +2,7 @@ package com.juick.api;
import com.juick.User;
import com.juick.json.MessageSerializer;
+import com.juick.server.MessagesQueries;
import com.juick.server.UserQueries;
import com.neovisionaries.ws.client.*;
import com.pengrad.telegrambot.BotUtils;
@@ -99,9 +100,10 @@ public class TelegramBotHook {
com.juick.Message jmsg = ms.deserialize(new JSONObject(text));
logger.info(String.format("got jmsg: %s", ms.serialize(jmsg).toString()));
StringBuilder sb = new StringBuilder();
- sb.append("Reply from @").append(jmsg.getUser().getUName()).append(":\n").append(jmsg.getText()).append("\n");
+ sb.append("Reply by @").append(jmsg.getUser().getUName()).append(":\n")
+ .append(getReplyQuote(jmsg.getMID(), jmsg.ReplyTo)).append("\n").append(jmsg.getText());
if (jmsg.getAttachmentURL() != null) {
- sb.append(jmsg.getAttachmentURL());
+ sb.append("\n").append(jmsg.getAttachmentURL());
}
String msg = sb.toString();
String msgUrl = String.format("https://juick.com/%d#%d", jmsg.getMID(), jmsg.getRID());
@@ -192,4 +194,24 @@ public class TelegramBotHook {
return jdbc.queryForList("SELECT tg_id FROM telegram INNER JOIN subscr_messages " +
"ON (telegram.user_id=subscr_messages.suser_id) WHERE message_id=? AND suser_id!=?", Long.class, mid, ignore_uid);
}
+ private String getReplyQuote(int MID, int ReplyTo) {
+ String quote = "";
+ if (ReplyTo > 0) {
+ com.juick.Message q = MessagesQueries.getReply(jdbc, MID, ReplyTo);
+ if (q != null) {
+ quote = q.getText();
+ }
+ } else {
+ com.juick.Message q = MessagesQueries.getMessage(jdbc, MID);
+ if (q != null) {
+ quote = q.getText();
+ }
+ }
+ if (quote.length() > 50) {
+ quote = ">" + quote.substring(0, 47).replace('\n', ' ') + "...\n";
+ } else if (quote.length() > 0) {
+ quote = ">" + quote.replace('\n', ' ') + "\n";
+ }
+ return quote;
+ }
}