diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/juick/www/api/Messages.java | 24 | ||||
-rw-r--r-- | src/main/java/com/juick/www/api/SystemActivity.java | 3 | ||||
-rw-r--r-- | src/test/java/com/juick/server/tests/ServerTests.java | 9 |
3 files changed, 27 insertions, 9 deletions
diff --git a/src/main/java/com/juick/www/api/Messages.java b/src/main/java/com/juick/www/api/Messages.java index a79088d0..2993e805 100644 --- a/src/main/java/com/juick/www/api/Messages.java +++ b/src/main/java/com/juick/www/api/Messages.java @@ -162,7 +162,8 @@ public class Messages { } @GetMapping("/api/thread") - public List<Message> getThread(@Visitor User visitor, @RequestParam(defaultValue = "0") int mid) { + public List<Message> getThread(@Visitor User visitor, @RequestParam(defaultValue = "0") int mid, + @RequestParam(defaultValue = "true") boolean showReplies) { Optional<Message> message = messagesService.getMessage(mid); if (message.isPresent()) { Message msg = message.get(); @@ -171,15 +172,20 @@ public class Messages { } else { msg.getUser().setAvatar(webApp.getAvatarUrl(msg.getUser())); msg.getRecommendations().forEach(r -> r.setAvatar(webApp.getAvatarUrl(r))); - List<Message> replies = messagesService.getReplies(visitor, mid); - // update replies counter to exclude banned replies - msg.setReplies(replies.size()); - if (!visitor.isAnonymous()) { - userService.updateLastSeen(visitor); - applicationEventPublisher.publishEvent(new SystemEvent(this, SystemActivity.read(visitor, msg))); + if (showReplies) { + List<Message> replies = messagesService.getReplies(visitor, mid); + // update replies counter to exclude banned replies + msg.setReplies(replies.size()); + if (!visitor.isAnonymous()) { + userService.updateLastSeen(visitor); + applicationEventPublisher + .publishEvent(new SystemEvent(this, SystemActivity.read(visitor, msg))); + } + replies.add(0, msg); + return replies; + } else { + return List.of(msg); } - replies.add(0, msg); - return replies; } } throw new HttpNotFoundException(); diff --git a/src/main/java/com/juick/www/api/SystemActivity.java b/src/main/java/com/juick/www/api/SystemActivity.java index 36bc3ad4..59d5cc73 100644 --- a/src/main/java/com/juick/www/api/SystemActivity.java +++ b/src/main/java/com/juick/www/api/SystemActivity.java @@ -23,6 +23,8 @@ import com.juick.model.User; import java.util.Collections; import java.util.List; +import javax.annotation.Nonnull; + public class SystemActivity { private SystemActivity(ActivityType type) { this.type = type; @@ -43,6 +45,7 @@ public class SystemActivity { return msg; } + @Nonnull public static SystemActivity read(User from, Message message) { var read = new SystemActivity(ActivityType.message); read.setFrom(from); diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index 87617cea..da777a92 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -213,6 +213,7 @@ import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.DigestUtils; import org.springframework.util.FileSystemUtils; import org.springframework.util.LinkedMultiValueMap; @@ -1025,6 +1026,7 @@ public class ServerTests { } @Test + @Transactional public void recommendTests() throws Exception { int mid = messagesService.createMessage(ugnich.getUid(), "to be liked", null, Set.of()); @@ -1037,6 +1039,13 @@ public class ServerTests { .andExpect(jsonPath("$[0].recommendations.length()", is(1))) .andExpect(jsonPath("$[0].recommendations[0].uname", is(freefdName))); mockMvc.perform(post("/api/like?mid=" + freefdMid + "&hash=" + freefdHash)).andExpect(status().isForbidden()); + messagesService.createReply(mid, 0, freefd, "reply", null); + mockMvc.perform(get("/api/thread?mid=" + mid + "&hash=" + freefdHash)).andExpect(status().isOk()) + .andExpect(jsonPath("$.length()", is(2))) + .andExpect(jsonPath("$[0].replies", is(1))); + mockMvc.perform(get("/api/thread?mid=" + mid + "&hash=" + freefdHash + "&showReplies=false")).andExpect(status().isOk()) + .andExpect(jsonPath("$.length()", is(1))) + .andExpect(jsonPath("$[0].replies", is(1))); } @Test |