diff options
author | Vitaly Takmazov | 2022-10-12 10:02:36 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2022-10-12 10:06:45 +0300 |
commit | 6b805c47528d34695a52aeece7162c4cc33ab856 (patch) | |
tree | b09d52dc6a9ae8a7779bc1bea723e469e02d20ab /src/main/java/com/juick/www/api/Messages.java | |
parent | 89c1e36e31c1cd7879b6a37723ae19960f430d97 (diff) |
API: add `showReplies` parameter to `/api/thread` endpoint
Diffstat (limited to 'src/main/java/com/juick/www/api/Messages.java')
-rw-r--r-- | src/main/java/com/juick/www/api/Messages.java | 24 |
1 files changed, 15 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(); |