aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-08-03 12:38:18 +0300
committerGravatar Vitaly Takmazov2018-08-03 12:38:18 +0300
commit162262eb58c4642b7ffb9ed41bc760e0f009d6a6 (patch)
treeb72b3b1807c561c61c3c40c27f07ba3e012acd73 /juick-server/src
parent798e8da8737c4fe5fee8dfaa7f98bfa13e2d91da (diff)
replies counter in feeds reflect banned comments
Diffstat (limited to 'juick-server/src')
-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
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java18
4 files changed, 32 insertions, 17 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());
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index c0141b2c..b468daff 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -878,7 +878,7 @@ public class ServerTests {
Message msg4 = messagesService.getMessage(mid1);
assertThat(msg4.getLikes(), is(0));
- assertThat(messagesService.getMessages(Collections.singletonList(mid1)).get(0).getLikes(), is(0));
+ assertThat(messagesService.getMessages(AnonymousUser.INSTANCE, Collections.singletonList(mid1)).get(0).getLikes(), is(0));
Assert.assertEquals(1, msg4.getReactions().stream().filter(r -> r.getId() == 2)
.findFirst().orElseThrow(IllegalStateException::new).getCount());
mockMvc.perform(post("/react?mid=" + mid1 + "&hash=" + freefdHash+ "&reactionId=1"))
@@ -931,18 +931,18 @@ public class ServerTests {
int mid = messagesService.createMessage(ugnich.getUid(), "yo", "jpg",
Collections.singletonList(banned));
privacyQueriesService.blacklistTag(freefd, banned);
- assertTrue(messagesService.getMessages(messagesService.getAll(freefd.getUid(), 0))
+ assertTrue(messagesService.getMessages(AnonymousUser.INSTANCE, messagesService.getAll(freefd.getUid(), 0))
.stream().noneMatch(m -> m.getTags().contains(banned)));
- assertFalse(messagesService.getMessages(messagesService.getAll(ugnich.getUid(), 0))
+ assertFalse(messagesService.getMessages(AnonymousUser.INSTANCE, messagesService.getAll(ugnich.getUid(), 0))
.stream().noneMatch(m -> m.getTags().contains(banned)));
- assertTrue(messagesService.getMessages(messagesService.getPhotos(freefd.getUid(), 0))
+ assertTrue(messagesService.getMessages(AnonymousUser.INSTANCE, messagesService.getPhotos(freefd.getUid(), 0))
.stream().noneMatch(m -> m.getTags().contains(banned)));
- assertFalse(messagesService.getMessages(messagesService.getPhotos(ugnich.getUid(), 0))
+ assertFalse(messagesService.getMessages(AnonymousUser.INSTANCE, messagesService.getPhotos(ugnich.getUid(), 0))
.stream().noneMatch(m -> m.getTags().contains(banned)));
jdbcTemplate.update("UPDATE messages SET popular=1 WHERE message_id=?", mid);
- assertTrue(messagesService.getMessages(messagesService.getPopular(freefd.getUid(), 0))
+ assertTrue(messagesService.getMessages(AnonymousUser.INSTANCE, messagesService.getPopular(freefd.getUid(), 0))
.stream().noneMatch(m -> m.getTags().contains(banned)));
- assertFalse(messagesService.getMessages(messagesService.getPopular(ugnich.getUid(), 0))
+ assertFalse(messagesService.getMessages(AnonymousUser.INSTANCE, messagesService.getPopular(ugnich.getUid(), 0))
.stream().noneMatch(m -> m.getTags().contains(banned)));
}
@@ -1066,9 +1066,13 @@ public class ServerTests {
reply = messagesService.getReply(mid, 5);
assertThat(userService.isReplyToBL(ugnich, reply), is(true));
assertThat(replies.size(), is(1));
+ List<Message> msgs = messagesService.getMessages(ugnich, Collections.singletonList(mid));
+ assertThat(msgs.get(0).getReplies(), is(1));
commandsManager.processCommand(ugnich, "BL @freefd", emptyUri);
messagesService.setRead(ugnich, mid);
assertThat(messagesService.getReplies(ugnich, mid).size(), is(5));
+ List<Message> nonblmsgs = messagesService.getMessages(ugnich, Collections.singletonList(mid));
+ assertThat(nonblmsgs.get(0).getReplies(), is(5));
}
@Test
public void cmykJpegShouldBeProcessedCorrectly() throws Exception {