aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/www
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/www')
-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);