aboutsummaryrefslogtreecommitdiff
path: root/juick-core/src/main/java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-10-19 15:56:01 +0300
committerGravatar Vitaly Takmazov2016-10-19 15:56:01 +0300
commitfabdccb6f9da49058a72ce69674ffcfe51f53002 (patch)
treed3d9944f5916f6913489f26fe3e882934bcb9422 /juick-core/src/main/java
parent36c679330d1bc0c6f0dfd7ec3dd1fb631259a8d9 (diff)
protocol: fix reply quote
Diffstat (limited to 'juick-core/src/main/java')
-rw-r--r--juick-core/src/main/java/com/juick/Message.java8
-rw-r--r--juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java12
-rw-r--r--juick-core/src/main/java/com/juick/server/MessagesQueries.java32
3 files changed, 36 insertions, 16 deletions
diff --git a/juick-core/src/main/java/com/juick/Message.java b/juick-core/src/main/java/com/juick/Message.java
index cb5fe92e..cc2381d8 100644
--- a/juick-core/src/main/java/com/juick/Message.java
+++ b/juick-core/src/main/java/com/juick/Message.java
@@ -58,6 +58,7 @@ public class Message implements Comparable {
public List<Message> childs = new ArrayList<>();
private PM PM;
private Recommendation Recommendation;
+ private String replyQuote;
public Message() {
}
@@ -254,4 +255,11 @@ public class Message implements Comparable {
public void setLiked(boolean liked) {
this.liked = liked;
}
+
+ public String getReplyQuote() {
+ return replyQuote;
+ }
+ public void setReplyQuote(String quote) {
+ replyQuote = quote;
+ }
}
diff --git a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java
index 37b0c6d3..6c712d28 100644
--- a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java
+++ b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java
@@ -10,7 +10,7 @@ public class PlainTextFormatter {
StringBuilder sb = new StringBuilder();
boolean isReply = jmsg.getRID() > 0;
String title = isReply ? "Reply by @" : "@";
- String subtitle = isReply ? getReplyQuote(jmsg) : jmsg.getTagsString();
+ String subtitle = isReply ? jmsg.getReplyQuote() : jmsg.getTagsString();
sb.append(title).append(jmsg.getUser().getUName()).append(":\n")
.append(subtitle).append("\n").append(jmsg.getText()).append("\n");
if (jmsg.Photo != null) {
@@ -25,14 +25,4 @@ public class PlainTextFormatter {
}
return "https://juick.com/" + jmsg.getMID();
}
-
- private static String getReplyQuote(Message msg) {
- String quote = msg.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;
- }
}
diff --git a/juick-core/src/main/java/com/juick/server/MessagesQueries.java b/juick-core/src/main/java/com/juick/server/MessagesQueries.java
index fa8881f3..40449e75 100644
--- a/juick-core/src/main/java/com/juick/server/MessagesQueries.java
+++ b/juick-core/src/main/java/com/juick/server/MessagesQueries.java
@@ -75,6 +75,7 @@ public class MessagesQueries {
}
msg.RepliesBy = rs.getString(19);
msg.setText(rs.getString(20));
+ msg.setReplyQuote(formatQuote(rs.getString(21)));
return msg;
}
}
@@ -247,7 +248,7 @@ public class MessagesQueries {
+ "messages.readonly,messages.privacy,messages.replies,"
+ "messages.attach,messages.place_id,messages.lat,"
+ "messages.lon,messages.likes,messages.hidden,"
- + "txt.tags,txt.repliesby,txt.txt FROM messages "
+ + "txt.tags,txt.repliesby,txt.txt, '' as q FROM messages "
+ "INNER JOIN users ON messages.user_id=users.id "
+ "INNER JOIN messages_txt AS txt "
+ "ON messages.message_id=txt.message_id "
@@ -262,8 +263,11 @@ public class MessagesQueries {
try {
return sql.queryForObject("SELECT replies.user_id,users.nick,"
+ "replies.replyto,replies.ts,"
- + "replies.attach,replies.txt FROM replies INNER JOIN users "
+ + "replies.attach,replies.txt, IFNULL(q.txt,t.txt) as quote FROM replies INNER JOIN users "
+ "ON replies.user_id=users.id "
+ + "LEFT JOIN replies q "
+ + "ON replies.message_id=q.message_id and replies.replyto=q.reply_id "
+ + "LEFT JOIN messages_txt t ON replies.message_id=t.message_id "
+ "WHERE replies.message_id=? AND replies.reply_id=?",
(rs, num) -> {
Message msg = new Message();
@@ -276,6 +280,10 @@ public class MessagesQueries {
msg.setDate(rs.getTimestamp(4));
msg.AttachmentType = rs.getString(5);
msg.setText(rs.getString(6));
+ String quote = rs.getString(7);
+ if (!StringUtils.isEmpty(quote)) {
+ msg.setReplyQuote(formatQuote(quote));
+ }
return msg;
}, mid, rid);
} catch (EmptyResultDataAccessException e) {
@@ -584,7 +592,7 @@ public class MessagesQueries {
+ "messages.readonly,messages.privacy,messages.replies,"
+ "messages.attach,messages.place_id,messages.lat,"
+ "messages.lon,messages.likes,messages.hidden,"
- + "messages_txt.tags,messages_txt.repliesby, messages_txt.txt "
+ + "messages_txt.tags,messages_txt.repliesby, messages_txt.txt, '' as q "
+ "FROM (messages INNER JOIN messages_txt "
+ "ON messages.message_id=messages_txt.message_id) "
+ "INNER JOIN users ON messages.user_id=users.id "
@@ -602,9 +610,14 @@ public class MessagesQueries {
"0 as readonly, 0 as privacy, 0 as replies," +
"replies.attach, 0 as place_id, 0 as lat," +
"0 as lon, 0 as likes, 0 as hidden," +
- "NULL as tags,NULL as repliesby, replies.txt " +
+ "NULL as tags,NULL as repliesby, replies.txt, " +
+ "IFNULL(qw.txt, t.txt) as q " +
"FROM replies INNER JOIN users " +
- "ON replies.user_id=users.id WHERE replies.message_id=? ORDER BY replies.reply_id ASC",
+ "ON replies.user_id=users.id " +
+ "LEFT JOIN replies qw ON replies.message_id=qw.message_id and replies.replyto=qw.reply_id " +
+ "LEFT JOIN messages_txt t on replies.message_id=t.message_id " +
+ "WHERE replies.message_id=? " +
+ "ORDER BY replies.reply_id ASC",
new MessageMapper(), mid, mid);
}
@@ -642,4 +655,13 @@ public class MessagesQueries {
return false;
}
+ private static String formatQuote(String quote) {
+ if (quote.length() > 50) {
+ quote = ">" + quote.substring(0, 47).replace('\n', ' ') + "...\n";
+ } else if (quote.length() > 0) {
+ quote = ">" + quote.replace('\n', ' ') + "\n";
+ }
+ return quote;
+ }
+
}