aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/www/api
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2022-10-12 10:02:36 +0300
committerGravatar Vitaly Takmazov2022-10-12 10:06:45 +0300
commit6b805c47528d34695a52aeece7162c4cc33ab856 (patch)
treeb09d52dc6a9ae8a7779bc1bea723e469e02d20ab /src/main/java/com/juick/www/api
parent89c1e36e31c1cd7879b6a37723ae19960f430d97 (diff)
API: add `showReplies` parameter to `/api/thread` endpoint
Diffstat (limited to 'src/main/java/com/juick/www/api')
-rw-r--r--src/main/java/com/juick/www/api/Messages.java24
-rw-r--r--src/main/java/com/juick/www/api/SystemActivity.java3
2 files changed, 18 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);