aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/service
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-10-06 21:26:54 +0300
committerGravatar Vitaly Takmazov2018-10-06 21:26:54 +0300
commit312b2408d72d11caf4d88cfbf07157ead220347f (patch)
treeb3c66d350ed6513526f37aa5a4d1df9600191f98 /juick-server/src/main/java/com/juick/service
parent8706a64c522ecfcd54577b4aac575a5ca4dba124 (diff)
Replies formatting for anonymous users
Diffstat (limited to 'juick-server/src/main/java/com/juick/service')
-rw-r--r--juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java38
1 files changed, 23 insertions, 15 deletions
diff --git a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
index b357ff92..d556865d 100644
--- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -90,12 +90,14 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
msg.setReplyQuote(MessageUtils.formatQuote(rs.getString(17)));
msg.setUpdated(rs.getTimestamp(18).toInstant());
int quoteUid = rs.getInt(19);
- if (quoteUid > 0) {
- User quoteUser = new User();
- quoteUser.setUid(quoteUid);
- quoteUser.setName(rs.getString(20));
- msg.setTo(quoteUser);
+ User quoteUser = new User();
+ quoteUser.setUid(quoteUid);
+ quoteUser.setName(rs.getString(20));
+ if (quoteUid == 0) {
+ quoteUser.setName(AnonymousUser.INSTANCE.getName());
+ quoteUser.setUri(URI.create(Optional.ofNullable(rs.getString(23)).orElse(StringUtils.EMPTY)));
}
+ msg.setTo(quoteUser);
msg.setUpdatedAt(rs.getTimestamp(21).toInstant());
if (StringUtils.isNotEmpty(msg.getAttachmentType())) {
try {
@@ -334,7 +336,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
+ "messages.readonly, messages.privacy, messages.replies,"
+ "messages.attach, COUNT(DISTINCT favorites.user_id) as likes, messages.hidden,"
+ "txt.tags, txt.repliesby, txt.txt, '' as q, messages.updated as updated, 0 as to_uid, "
- + "NULL as to_name, txt.updated_at, '' as uri FROM messages "
+ + "NULL as to_name, txt.updated_at, '' as uri, '' as to_uri FROM messages "
+ "INNER JOIN users ON messages.user_id = users.id "
+ "INNER JOIN messages_txt AS txt "
+ "ON messages.message_id = txt.message_id "
@@ -362,7 +364,8 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
+ "replies.replyto, replies.ts,"
+ "replies.attach, replies.txt, IFNULL(q.txt,t.txt) as quote, "
+ "COALESCE(q.user_id, m.user_id) AS to_uid, COALESCE(qu.nick, mu.nick) AS to_name, "
- + "replies.updated_at, replies.user_uri as uri "
+ + "replies.updated_at, replies.user_uri as uri, "
+ + "q.user_uri AS to_uri "
+ "FROM replies LEFT 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 "
@@ -378,6 +381,11 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
msg.setUser(new User());
msg.getUser().setUid(rs.getInt(1));
msg.getUser().setName(rs.getString(2));
+ if (msg.getUser().getUid() == 0) {
+ msg.getUser().setName(AnonymousUser.INSTANCE.getName());
+ msg.getUser().setUri(
+ URI.create(Optional.ofNullable(rs.getString(11)).orElse(StringUtils.EMPTY)));
+ }
msg.setReplyto(rs.getInt(3));
msg.setTimestamp(rs.getTimestamp(4).toInstant());
msg.setAttachmentType(rs.getString(5));
@@ -388,12 +396,11 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
msg.setReplyQuote(MessageUtils.formatQuote(quote));
}
int quoteUid = rs.getInt(8);
- if (quoteUid > 0) {
- User quoteUser = new User();
- quoteUser.setUid(quoteUid);
- quoteUser.setName(rs.getString(9));
- msg.setTo(quoteUser);
- }
+ User quoteUser = new User();
+ quoteUser.setUid(quoteUid);
+ quoteUser.setName(Optional.ofNullable(rs.getString(9)).orElse(AnonymousUser.INSTANCE.getName()));
+ quoteUser.setUri(URI.create(Optional.ofNullable(rs.getString(11)).orElse(StringUtils.EMPTY)));
+ msg.setTo(quoteUser);
msg.setUpdatedAt(rs.getTimestamp(10).toInstant());
if (StringUtils.isNotEmpty(msg.getAttachmentType())) {
try {
@@ -824,7 +831,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
+ "messages.readonly,messages.privacy, messages.replies-COUNT(DISTINCT banned.reply_id) as replies,"
+ "messages.attach,COUNT(DISTINCT favorites.user_id) AS likes,messages.hidden,"
+ "messages_txt.tags,messages_txt.repliesby, messages_txt.txt, '' as q, "
- + "messages.updated, 0 as to_uid, NULL as to_name, messages_txt.updated_at, '' as uri "
+ + "messages.updated, 0 as to_uid, NULL as to_name, messages_txt.updated_at, '' as uri, '' as to_uri "
+ "FROM (messages INNER JOIN messages_txt "
+ "ON messages.message_id=messages_txt.message_id) "
+ "INNER JOIN users ON messages.user_id=users.id "
@@ -901,7 +908,8 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
"IFNULL(qw.txt, t.txt) as q, " +
"NOW(), " +
"COALESCE(qw.user_id, m.user_id) as to_uid, COALESCE(qu.nick, mu.nick) as to_name, " +
- "replies.updated_at, replies.user_uri as uri " +
+ "replies.updated_at, replies.user_uri as uri, " +
+ "qw.user_uri as to_uri " +
"FROM replies LEFT JOIN users " +
"ON replies.user_id = users.id " +
"LEFT JOIN replies qw ON replies.message_id = qw.message_id and replies.replyto = qw.reply_id " +