aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/api/Messages.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-11-20 16:37:42 +0300
committerGravatar Vitaly Takmazov2018-11-20 16:37:42 +0300
commita3ec3587e1fa33e4e08da9783d9d66c55ac84550 (patch)
tree9311de2f6511421eefed3e2e10bc821d2179dbd4 /src/main/java/com/juick/server/api/Messages.java
parentd2b04d9b719b79a35e90b1c5569722ba5cbf794b (diff)
avatar public url
Diffstat (limited to 'src/main/java/com/juick/server/api/Messages.java')
-rw-r--r--src/main/java/com/juick/server/api/Messages.java18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/main/java/com/juick/server/api/Messages.java b/src/main/java/com/juick/server/api/Messages.java
index f7485d55..8aae0d57 100644
--- a/src/main/java/com/juick/server/api/Messages.java
+++ b/src/main/java/com/juick/server/api/Messages.java
@@ -21,6 +21,7 @@ import com.juick.Message;
import com.juick.Tag;
import com.juick.User;
import com.juick.server.Utils;
+import com.juick.server.www.WebApp;
import com.juick.service.component.MessageReadEvent;
import com.juick.model.CommandResult;
import com.juick.server.util.HttpBadRequestException;
@@ -64,6 +65,8 @@ public class Messages {
private TagService tagService;
@Inject
private ApplicationEventPublisher applicationEventPublisher;
+ @Inject
+ private WebApp webApp;
// TODO: serialize image urls
@@ -74,7 +77,9 @@ public class Messages {
if (!visitor.isAnonymous()) {
int vuid = visitor.getUid();
List<Integer> mids = messagesService.getMyFeed(vuid, before_mid, true);
- return ResponseEntity.ok(messagesService.getMessages(visitor, mids));
+ List<Message> msgs = messagesService.getMessages(visitor, mids);
+ msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarPublicUrl(m.getUser())));
+ return ResponseEntity.ok(msgs);
}
return FORBIDDEN;
}
@@ -92,7 +97,6 @@ public class Messages {
@RequestParam(required = false) String tag) {
User visitor = UserUtils.getCurrentUser();
-
List<Integer> mids;
if (!StringUtils.isEmpty(uname)) {
User user = userService.getUserByName(uname);
@@ -136,7 +140,9 @@ public class Messages {
mids = messagesService.getAll(visitor.getUid(), before);
}
}
- return ResponseEntity.ok(messagesService.getMessages(visitor, mids));
+ List<Message> msgs = messagesService.getMessages(visitor, mids);
+ msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarPublicUrl(m.getUser())));
+ return ResponseEntity.ok(msgs);
}
@DeleteMapping("/api/messages")
public CommandResult deleteMessage(@RequestParam int mid, @RequestParam(required = false, defaultValue = "0") int rid) {
@@ -154,7 +160,9 @@ public class Messages {
@GetMapping("/api/messages/discussions")
public List<Message> getDiscussions(
@RequestParam(required = false, defaultValue = "0") Long to) {
- return messagesService.getMessages(UserUtils.getCurrentUser(), messagesService.getDiscussions(UserUtils.getCurrentUser().getUid(), to));
+ List<Message> msgs = messagesService.getMessages(UserUtils.getCurrentUser(), messagesService.getDiscussions(UserUtils.getCurrentUser().getUid(), to));
+ msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarPublicUrl(m.getUser())));
+ return msgs;
}
@GetMapping("/api/thread")
public ResponseEntity<List<com.juick.Message>> getThread(
@@ -169,8 +177,10 @@ public class Messages {
if (userService.getUserByName(msg.getUser().getName()).isBanned()) {
throw new HttpNotFoundException();
}
+ msg.getUser().setAvatar(webApp.getAvatarPublicUrl(msg.getUser()));
msg.setRecommendations(new HashSet<>(messagesService.getMessageRecommendations(msg.getMid())));
List<com.juick.Message> replies = messagesService.getReplies(visitor, mid);
+ replies.forEach(m -> m.getUser().setAvatar(webApp.getAvatarPublicUrl(m.getUser())));
if (!visitor.isAnonymous()) {
userService.updateLastSeen(visitor);
applicationEventPublisher.publishEvent(