From 2788060f586efb13cce6fa2b11dbfee630546ece Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 23 Mar 2022 00:32:57 +0300 Subject: Return correct replies counter on /thread API endpoint * replies counter will not include replies from banned users now --- src/main/java/com/juick/www/api/Messages.java | 2 ++ src/test/java/com/juick/server/tests/ServerTests.java | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/main/java/com/juick/www/api/Messages.java b/src/main/java/com/juick/www/api/Messages.java index a782f680..ab222a3c 100644 --- a/src/main/java/com/juick/www/api/Messages.java +++ b/src/main/java/com/juick/www/api/Messages.java @@ -175,6 +175,8 @@ public class Messages { .map(Pair::getRight).collect(Collectors.toList()))); msg.getRecommendations().forEach(r -> r.setAvatar(webApp.getAvatarUrl(r))); List replies = messagesService.getReplies(visitor, mid); + // update replies counter to exclude banned replies + msg.setReplies(replies.size()); replies.forEach(m -> m.getUser().setAvatar(webApp.getAvatarUrl(m.getUser()))); if (!visitor.isAnonymous()) { userService.updateLastSeen(visitor); diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index 8cff4826..18aa41f7 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -1274,6 +1274,9 @@ public class ServerTests { assertThat(messagesService.getMessage(mid).get().getReplies(), is(4)); replies = messagesService.getReplies(ugnich, mid); assertThat(replies.size(), is(1)); + mockMvc.perform(get("/api/thread").with(httpBasic(ugnichName, ugnichPassword)).param("mid", + String.valueOf(mid))) + .andExpect(jsonPath("$[0].replies", is(1))); commandsManager.processCommand(serviceUser, String.format("#%d/4 mmm?!", mid), emptyUri); assertThat(messagesService.getMessage(mid).get().getReplies(), is(5)); replies = messagesService.getReplies(ugnich, mid); -- cgit v1.2.3