aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src/main/java/com')
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Messages.java6
-rw-r--r--juick-server/src/main/java/com/juick/server/api/rss/Feeds.java5
-rw-r--r--juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java20
3 files changed, 21 insertions, 10 deletions
diff --git a/juick-server/src/main/java/com/juick/server/api/Messages.java b/juick-server/src/main/java/com/juick/server/api/Messages.java
index eb562103..d7c07391 100644
--- a/juick-server/src/main/java/com/juick/server/api/Messages.java
+++ b/juick-server/src/main/java/com/juick/server/api/Messages.java
@@ -76,7 +76,7 @@ public class Messages {
if (!visitor.isAnonymous()) {
int vuid = visitor.getUid();
List<Integer> mids = messagesService.getMyFeed(vuid, before_mid, true);
- return ResponseEntity.ok(messagesService.getMessages(mids));
+ return ResponseEntity.ok(messagesService.getMessages(visitor, mids));
}
return FORBIDDEN;
}
@@ -138,7 +138,7 @@ public class Messages {
mids = messagesService.getAll(visitor.getUid(), before);
}
}
- return ResponseEntity.ok(messagesService.getMessages(mids));
+ return ResponseEntity.ok(messagesService.getMessages(visitor, mids));
}
@DeleteMapping("/messages")
public CommandResult deleteMessage(@RequestParam int mid, @RequestParam(required = false, defaultValue = "0") int rid) {
@@ -156,7 +156,7 @@ public class Messages {
@GetMapping("/messages/discussions")
public List<Message> getDiscussions(
@RequestParam(required = false, defaultValue = "0") Long to) {
- return messagesService.getMessages(messagesService.getDiscussions(UserUtils.getCurrentUser().getUid(), to));
+ return messagesService.getMessages(UserUtils.getCurrentUser(), messagesService.getDiscussions(UserUtils.getCurrentUser().getUid(), to));
}
@GetMapping("/thread")
public ResponseEntity<List<com.juick.Message>> getThread(
diff --git a/juick-server/src/main/java/com/juick/server/api/rss/Feeds.java b/juick-server/src/main/java/com/juick/server/api/rss/Feeds.java
index d2d112d8..ebf5b04e 100644
--- a/juick-server/src/main/java/com/juick/server/api/rss/Feeds.java
+++ b/juick-server/src/main/java/com/juick/server/api/rss/Feeds.java
@@ -19,6 +19,7 @@ package com.juick.server.api.rss;
import com.juick.User;
import com.juick.server.util.HttpBadRequestException;
+import com.juick.server.util.UserUtils;
import com.juick.service.MessagesService;
import com.juick.service.UserService;
import org.springframework.stereotype.Controller;
@@ -50,7 +51,7 @@ public class Feeds {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("messagesView");
modelAndView.addObject("user", user);
- modelAndView.addObject("messages", messagesService.getMessages(mids));
+ modelAndView.addObject("messages", messagesService.getMessages(UserUtils.getCurrentUser(), mids));
return modelAndView;
}
throw new HttpBadRequestException();
@@ -61,7 +62,7 @@ public class Feeds {
List<Integer> mids = messagesService.getLastMessages(hours);
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("messagesView");
- modelAndView.addObject("messages", messagesService.getMessages(mids));
+ modelAndView.addObject("messages", messagesService.getMessages(UserUtils.getCurrentUser(),mids));
return modelAndView;
}
@RequestMapping(value = "/rss/comments", method = RequestMethod.GET)
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 75493377..f79e4142 100644
--- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -754,14 +754,20 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Transactional(readOnly = true)
@Override
- public List<com.juick.Message> getMessages(final List<Integer> mids) {
+ public List<com.juick.Message> getMessages(final User visitor, final List<Integer> mids) {
if (CollectionUtils.isNotEmpty(mids)) {
List<com.juick.Message> msgs = getNamedParameterJdbcTemplate().query(
- "SELECT messages.message_id, 0 as rid, 0 as replyto, "
+ "WITH RECURSIVE banned(message_id, reply_id) "
+ + "AS (SELECT message_id, reply_id FROM replies WHERE replies.message_id IN (:ids) "
+ + "AND EXISTS (SELECT 1 FROM bl_users b WHERE b.user_id = :uid AND b.bl_user_id = replies.user_id) "
+ + "UNION ALL SELECT replies.message_id, replies.reply_id FROM replies INNER JOIN banned "
+ + "ON banned.reply_id = replies.replyto AND banned.message_id=replies.message_id "
+ + "WHERE replies.message_id IN (:ids)) "
+ + "SELECT messages.message_id, 0 as rid, 0 as replyto, "
+ "messages.user_id,users.nick, 0 as banned, "
+ "messages.ts,"
- + "messages.readonly,messages.privacy,messages.replies,"
+ + "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 "
@@ -770,8 +776,12 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
+ "INNER JOIN users ON messages.user_id=users.id "
+ "LEFT JOIN favorites "
+ "ON messages.message_id = favorites.message_id AND favorites.like_id=1 "
- + "WHERE messages.message_id IN (:ids) GROUP BY messages.message_id",
- new MapSqlParameterSource("ids", mids),
+ + "LEFT JOIN banned "
+ + "ON messages.message_id = banned.message_id "
+ + "WHERE messages.message_id IN (:ids) GROUP BY "
+ + "messages.message_id, rid, replyto, messages.user_id, users.nick, banned, messages.ts, messages.readonly, messages.privacy, messages.attach, messages.hidden, messages_txt.tags, messages_txt.repliesby, messages_txt.txt, q, messages.updated, to_uid, to_name",
+ new MapSqlParameterSource("ids", mids)
+ .addValue("uid", visitor.getUid()),
new MessageMapper());