aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/server/api')
-rw-r--r--src/main/java/com/juick/server/api/Messages.java18
-rw-r--r--src/main/java/com/juick/server/api/PM.java9
-rw-r--r--src/main/java/com/juick/server/api/Users.java19
-rw-r--r--src/main/java/com/juick/server/api/activity/Profile.java5
-rw-r--r--src/main/java/com/juick/server/api/rss/MessagesView.java7
5 files changed, 47 insertions, 11 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(
diff --git a/src/main/java/com/juick/server/api/PM.java b/src/main/java/com/juick/server/api/PM.java
index 0c36fe00..e00a4c97 100644
--- a/src/main/java/com/juick/server/api/PM.java
+++ b/src/main/java/com/juick/server/api/PM.java
@@ -18,7 +18,9 @@
package com.juick.server.api;
import com.juick.Chat;
+import com.juick.Message;
import com.juick.User;
+import com.juick.server.www.WebApp;
import com.juick.service.component.MessageEvent;
import com.juick.model.AnonymousUser;
import com.juick.model.PrivateChats;
@@ -47,6 +49,8 @@ public class PM {
private PMQueriesService pmQueriesService;
@Inject
private ApplicationEventPublisher applicationEventPublisher;
+ @Inject
+ private WebApp webApp;
@RequestMapping(value = "/api/pm", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public List<com.juick.Message> doGetPM(
@@ -64,7 +68,9 @@ public class PM {
throw new HttpBadRequestException();
}
- return pmQueriesService.getPMMessages(visitor.getUid(), uid);
+ List<Message> msgs = pmQueriesService.getPMMessages(visitor.getUid(), uid);
+ msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarPublicUrl(m.getUser())));
+ return msgs;
}
@RequestMapping(value = "/api/pm", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@@ -109,6 +115,7 @@ public class PM {
// TODO: ignore cnt param for now but make sure paging param will not be cnt
List<Chat> lastconv = pmQueriesService.getLastChats(visitor);
+ lastconv.forEach(c -> c.setAvatar(webApp.getAvatarPublicUrl(c)));
PrivateChats pms = new PrivateChats();
pms.setUsers(lastconv);
return pms;
diff --git a/src/main/java/com/juick/server/api/Users.java b/src/main/java/com/juick/server/api/Users.java
index 7686d722..791071a5 100644
--- a/src/main/java/com/juick/server/api/Users.java
+++ b/src/main/java/com/juick/server/api/Users.java
@@ -22,6 +22,7 @@ import com.juick.model.ApplicationStatus;
import com.juick.model.UserInfo;
import com.juick.server.util.HttpForbiddenException;
import com.juick.server.util.HttpNotFoundException;
+import com.juick.server.www.WebApp;
import com.juick.service.CrosspostService;
import com.juick.service.EmailService;
import com.juick.service.MessagesService;
@@ -49,6 +50,8 @@ public class Users {
private CrosspostService crosspostService;
@Inject
private EmailService emailService;
+ @Inject
+ private WebApp webApp;
@RequestMapping(value = "/api/auth", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public String getAuthToken() {
@@ -66,11 +69,13 @@ public class Users {
if (!unames.isEmpty() && unames.size() < 20)
users.addAll(userService.getUsersByName(unames));
}
-
+ users.forEach(u -> u.setAvatar(webApp.getAvatarPublicUrl(u)));
if (!users.isEmpty())
return users;
if (!UserUtils.getCurrentUser().isAnonymous()) {
- return Collections.singletonList(UserUtils.getCurrentUser());
+ User visitor = UserUtils.getCurrentUser();
+ visitor.setAvatar(webApp.getAvatarPublicUrl(visitor));
+ return Collections.singletonList(visitor);
}
throw new HttpNotFoundException();
@@ -88,6 +93,7 @@ public class Users {
me.setUnreadCount(unread.size());
me.setRead(userService.getUserFriends(visitor.getUid()));
me.setReaders(userService.getUserReaders(visitor.getUid()));
+ me.setAvatar(webApp.getAvatarPublicUrl(visitor));
return me;
}
@@ -111,7 +117,9 @@ public class Users {
}
if (uid > 0) {
- return userService.getUserFriends(uid);
+ List<User> friends = userService.getUserFriends(uid);
+ friends.forEach(f -> f.setAvatar(webApp.getAvatarPublicUrl(f)));
+ return friends;
}
throw new HttpNotFoundException();
}
@@ -136,7 +144,9 @@ public class Users {
}
if (uid > 0) {
- return userService.getUserReaders(uid);
+ List<User> readers = userService.getUserReaders(uid);
+ readers.forEach(r -> r.setAvatar(webApp.getAvatarPublicUrl(r)));
+ return readers;
}
throw new HttpNotFoundException();
}
@@ -145,6 +155,7 @@ public class Users {
public UserInfo getUserInfo(@PathVariable String uname) {
User user = userService.getUserByName(uname);
if (!user.isBanned()) {
+ user.setAvatar(webApp.getAvatarPublicUrl(user));
return userService.getUserInfo(user);
}
throw new HttpNotFoundException();
diff --git a/src/main/java/com/juick/server/api/activity/Profile.java b/src/main/java/com/juick/server/api/activity/Profile.java
index f4160eab..60e099d0 100644
--- a/src/main/java/com/juick/server/api/activity/Profile.java
+++ b/src/main/java/com/juick/server/api/activity/Profile.java
@@ -24,6 +24,7 @@ import com.juick.server.api.activity.model.objects.Person;
import com.juick.server.util.HttpBadRequestException;
import com.juick.server.util.HttpNotFoundException;
import com.juick.server.util.UserUtils;
+import com.juick.server.www.WebApp;
import com.juick.service.MessagesService;
import com.juick.service.UserService;
import com.juick.service.activities.DeleteUserEvent;
@@ -81,6 +82,8 @@ public class Profile {
private String baseImagesUri;
@Inject
private ObjectMapper jsonMapper;
+ @Inject
+ private WebApp webApp;
@GetMapping(value = "/u/{userName}", produces = {Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE})
public Person getUser(@PathVariable String userName) {
@@ -101,7 +104,7 @@ public class Profile {
person.setFollowers(activityPubManager.followersUri(user));
person.setFollowing(activityPubManager.followingUri(user));
UriComponentsBuilder image = UriComponentsBuilder.fromUriString(baseImagesUri);
- image.path(String.format("/a/%d.png", user.getUid()));
+ image.path(webApp.getAvatarPublicUrl(user));
Image avatar = new Image();
avatar.setUrl(image.toUriString());
avatar.setMediaType("image/png");
diff --git a/src/main/java/com/juick/server/api/rss/MessagesView.java b/src/main/java/com/juick/server/api/rss/MessagesView.java
index c0ae4a97..4b29108e 100644
--- a/src/main/java/com/juick/server/api/rss/MessagesView.java
+++ b/src/main/java/com/juick/server/api/rss/MessagesView.java
@@ -21,6 +21,7 @@ import com.juick.Message;
import com.juick.User;
import com.juick.server.api.rss.extension.JuickModule;
import com.juick.server.api.rss.extension.JuickModuleImpl;
+import com.juick.server.www.WebApp;
import com.juick.util.MessageUtils;
import com.rometools.modules.atom.modules.AtomLinkModule;
import com.rometools.modules.atom.modules.AtomLinkModuleImpl;
@@ -40,6 +41,7 @@ import org.springframework.web.servlet.view.feed.AbstractRssFeedView;
import javax.annotation.Nonnull;
import javax.annotation.PostConstruct;
+import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URI;
@@ -57,6 +59,9 @@ public class MessagesView extends AbstractRssFeedView {
private static final Logger logger = LoggerFactory.getLogger(MessagesView.class);
+ @Inject
+ private WebApp webApp;
+
@PostConstruct
public void init() {
setContentType("application/rss+xml;charset=UTF-8");
@@ -82,7 +87,7 @@ public class MessagesView extends AbstractRssFeedView {
String link = String.format("http://juick.com/%s/", user.getName());
feed.setLink(link);
Image rssImage = new Image();
- rssImage.setUrl(String.format("http://juick.com/a/%d.png", user.getUid()));
+ rssImage.setUrl(webApp.getAvatarPublicUrl(user));
rssImage.setTitle(title);
rssImage.setLink(link);
feed.setImage(rssImage);