aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-05-19 20:50:09 +0300
committerGravatar Vitaly Takmazov2016-05-19 20:50:09 +0300
commitb4e6e2092606afb2a321fd07f5bdb687ef03356e (patch)
tree32caf265f29fd978e1113ecfa1dae8af416cc625 /src/main/java/com
parent9be74d0e4b5c62e54685483b132c0311bc8aed2a (diff)
telegram reply quote
Diffstat (limited to 'src/main/java/com')
-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;
+ }
}