diff options
author | Vitaly Takmazov | 2018-11-20 16:37:42 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-11-20 16:37:42 +0300 |
commit | a3ec3587e1fa33e4e08da9783d9d66c55ac84550 (patch) | |
tree | 9311de2f6511421eefed3e2e10bc821d2179dbd4 | |
parent | d2b04d9b719b79a35e90b1c5569722ba5cbf794b (diff) |
avatar public url
13 files changed, 87 insertions, 43 deletions
diff --git a/src/main/java/com/juick/server/XMPPConnection.java b/src/main/java/com/juick/server/XMPPConnection.java index 0adc7796..74e281c9 100644 --- a/src/main/java/com/juick/server/XMPPConnection.java +++ b/src/main/java/com/juick/server/XMPPConnection.java @@ -19,6 +19,7 @@ package com.juick.server; import com.juick.User; import com.juick.formatters.PlainTextFormatter; +import com.juick.server.www.WebApp; import com.juick.service.component.*; import com.juick.model.CommandResult; import com.juick.model.UserInfo; @@ -118,6 +119,8 @@ public class XMPPConnection implements StanzaListener, NotificationListener { private ApplicationEventPublisher applicationEventPublisher; @Value("${service_user:juick}") private String serviceUsername; + @Inject + private WebApp webApp; private User serviceUser; @@ -170,11 +173,11 @@ public class XMPPConnection implements StanzaListener, NotificationListener { userVCard.setFormattedName(info.getFullName()); userVCard.setNickname(user.getName()); try { - userVCard.setPhoto(new VCard.Image(new URI("http://i.juick.com/a/" + user.getUid() + ".png"))); + userVCard.setPhoto(new VCard.Image(URI.create(webApp.getAvatarPublicUrl(user)))); if (info.getUrl() != null) { userVCard.setUrl(new URL(info.getUrl())); } - } catch (MalformedURLException | URISyntaxException e) { + } catch (MalformedURLException e) { logger.warn("url exception", e); } return iq.createResult(userVCard); 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); diff --git a/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java b/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java index 2286165d..93fe7282 100644 --- a/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java +++ b/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java @@ -58,8 +58,8 @@ public class WwwAppConfiguration implements WebMvcConfigurer { private UserService userService; @Inject private TagService tagService; - @Value("${avatars_path:#{systemEnvironment['TEMP'] ?: '/tmp'}}") - private String avatarsPath; + @Value("${img_path:#{systemEnvironment['TEMP'] ?: '/tmp'}}") + private String imgDir; @Bean public CaffeineCacheManager cacheManager() { return new CaffeineCacheManager("help"); @@ -131,7 +131,7 @@ public class WwwAppConfiguration implements WebMvcConfigurer { try { registry .addResourceHandler("/**", "/i/a/**") - .addResourceLocations("classpath:/static/", Paths.get(avatarsPath, "/a/").toUri().toURL().toString()) + .addResourceLocations("classpath:/static/", Paths.get(imgDir, "/a/").toUri().toURL().toString()) .setCacheControl(CacheControl.maxAge(365, TimeUnit.DAYS)) .resourceChain(false) .addResolver(new VersionResourceResolver().addContentVersionStrategy("/**", "/i/a/**")); diff --git a/src/main/java/com/juick/server/www/WebApp.java b/src/main/java/com/juick/server/www/WebApp.java index d2729c89..3ab09de2 100644 --- a/src/main/java/com/juick/server/www/WebApp.java +++ b/src/main/java/com/juick/server/www/WebApp.java @@ -20,12 +20,12 @@ import com.juick.Tag; import com.juick.User; import com.juick.service.TagService; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.web.servlet.resource.ResourceUrlProvider; +import org.springframework.web.util.UriComponentsBuilder; -import javax.annotation.PostConstruct; import javax.inject.Inject; -import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -41,6 +41,8 @@ public class WebApp { private TagService tagService; @Inject private ResourceUrlProvider resourceUrlProvider; + @Value("${img_url:http://localhost:8080/i/}") + private String baseImagesUri; public List<Tag> parseTags(String tagsStr) { List<Tag> tags = new ArrayList<>(); @@ -70,11 +72,15 @@ public class WebApp { public String getScriptsUrl() { return resourceUrlProvider.getForLookupPath("/scripts.js"); } - public String getAvatarUrl(User user) { + public String getAvatarWebPath(User user) { String avatarUri = resourceUrlProvider.getForLookupPath(String.format("/i/a/%d.png", user.getUid())); if (StringUtils.isNotEmpty(avatarUri)) { return avatarUri; } return resourceUrlProvider.getForLookupPath("/av-96.png"); } + public String getAvatarPublicUrl(User user) { + UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseImagesUri); + return uri.replacePath(getAvatarWebPath(user)).toUriString(); + } } diff --git a/src/main/java/com/juick/server/www/controllers/Help.java b/src/main/java/com/juick/server/www/controllers/Help.java index e2a89bd6..12abee80 100644 --- a/src/main/java/com/juick/server/www/controllers/Help.java +++ b/src/main/java/com/juick/server/www/controllers/Help.java @@ -59,7 +59,7 @@ public class Help { @PathVariable(required = false, name = "langOrPage") String langOrPage, Model model) throws IOException, URISyntaxException { com.juick.User visitor = UserUtils.getCurrentUser(); - visitor.setAvatar(webApp.getAvatarUrl(visitor)); + visitor.setAvatar(webApp.getAvatarWebPath(visitor)); String navigation = null; if (langOrPage != null) { diff --git a/src/main/java/com/juick/server/www/controllers/MessagesWWW.java b/src/main/java/com/juick/server/www/controllers/MessagesWWW.java index 9ccd099b..ba8e7b66 100644 --- a/src/main/java/com/juick/server/www/controllers/MessagesWWW.java +++ b/src/main/java/com/juick/server/www/controllers/MessagesWWW.java @@ -30,7 +30,6 @@ import com.juick.util.MessageUtils; import org.apache.commons.codec.CharEncoding; import org.apache.commons.lang3.StringUtils; import org.apache.commons.text.StringEscapeUtils; -import org.springframework.context.ApplicationEventPublisher; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -72,7 +71,7 @@ public class MessagesWWW { private WebApp webApp; private void fillUserModel(ModelMap model, com.juick.User user, com.juick.User visitor) { - user.setAvatar(webApp.getAvatarUrl(user)); + user.setAvatar(webApp.getAvatarWebPath(user)); model.addAttribute("user", user); model.addAttribute("isSubscribed", userService.isSubscribed(visitor.getUid(), user.getUid())); model.addAttribute("isInBL", userService.isInBL(visitor.getUid(), user.getUid())); @@ -102,7 +101,7 @@ public class MessagesWWW { } com.juick.User visitor = UserUtils.getCurrentUser(); - visitor.setAvatar(webApp.getAvatarUrl(visitor)); + visitor.setAvatar(webApp.getAvatarWebPath(visitor)); if (paramSearch != null && paramSearch.length() > 64) { paramSearch = null; @@ -156,7 +155,7 @@ public class MessagesWWW { model.addAttribute("visitor", visitor); model.addAttribute("noindex", !(paramShow == null && paramBefore == 0)); List<com.juick.Message> msgs = messagesService.getMessages(visitor, mids); - msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarUrl(m.getUser()))); + msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarWebPath(m.getUser()))); if (!visitor.isAnonymous()) { fillUserModel(model, visitor, visitor); List<Integer> unread = messagesService.getUnread(visitor); @@ -208,7 +207,7 @@ public class MessagesWWW { if (user.isBanned() || user.isAnonymous()) { throw new HttpNotFoundException(); } - visitor.setAvatar(webApp.getAvatarUrl(visitor)); + visitor.setAvatar(webApp.getAvatarWebPath(visitor)); List<Integer> mids; @@ -275,7 +274,7 @@ public class MessagesWWW { fillUserModel(model, user, visitor); model.addAttribute("paramTag", paramTag); List<com.juick.Message> msgs = messagesService.getMessages(visitor, mids); - msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarUrl(m.getUser()))); + msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarWebPath(m.getUser()))); if (!visitor.isAnonymous()) { List<Integer> unread = messagesService.getUnread(visitor); visitor.setUnreadCount(unread.size()); @@ -320,7 +319,7 @@ public class MessagesWWW { if (visitor.isBanned()) { throw new HttpNotFoundException(); } - visitor.setAvatar(webApp.getAvatarUrl(visitor)); + visitor.setAvatar(webApp.getAvatarWebPath(visitor)); model.addAttribute("title", "Теги " + user.getName()); model.addAttribute("headers", "<meta name=\"robots\" content=\"noindex,nofollow\"/>"); @@ -339,7 +338,7 @@ public class MessagesWWW { if (visitor.isBanned()) { throw new HttpNotFoundException(); } - visitor.setAvatar(webApp.getAvatarUrl(visitor)); + visitor.setAvatar(webApp.getAvatarWebPath(visitor)); model.addAttribute("title", "Подписки " + user.getName()); model.addAttribute("headers", "<meta name=\"robots\" content=\"noindex\"/>"); model.addAttribute("visitor", visitor); @@ -356,7 +355,7 @@ public class MessagesWWW { if (visitor.isBanned()) { throw new HttpForbiddenException(); } - visitor.setAvatar(webApp.getAvatarUrl(visitor)); + visitor.setAvatar(webApp.getAvatarWebPath(visitor)); model.addAttribute("title", "Читатели " + user.getName()); model.addAttribute("headers", "<meta name=\"robots\" content=\"noindex\"/>"); model.addAttribute("visitor", visitor); @@ -373,7 +372,7 @@ public class MessagesWWW { if (visitor.isBanned() || visitor.getUid() != user.getUid()) { throw new HttpForbiddenException(); } - visitor.setAvatar(webApp.getAvatarUrl(visitor)); + visitor.setAvatar(webApp.getAvatarWebPath(visitor)); model.addAttribute("title", "Черный список " + user.getName()); model.addAttribute("headers", "<meta name=\"robots\" content=\"noindex\"/>"); model.addAttribute("visitor", visitor); @@ -389,7 +388,7 @@ public class MessagesWWW { @RequestParam(required = false, defaultValue = "0") int before, ModelMap model) throws IOException { com.juick.User visitor = UserUtils.getCurrentUser(); - visitor.setAvatar(webApp.getAvatarUrl(visitor)); + visitor.setAvatar(webApp.getAvatarWebPath(visitor)); String paramTagStr = StringEscapeUtils.unescapeHtml4(tagName); com.juick.Tag paramTag = tagService.getTag(paramTagStr, false); if (paramTag == null) { @@ -413,7 +412,7 @@ public class MessagesWWW { model.addAttribute("title", title); List<Integer> mids = messagesService.getTag(paramTag.TID, visitor.getUid(), before, (visitor.isAnonymous()) ? 40 : 20); List<com.juick.Message> msgs = messagesService.getMessages(visitor, mids); - msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarUrl(m.getUser()))); + msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarWebPath(m.getUser()))); if (!visitor.isAnonymous()) { List<Integer> unread = messagesService.getUnread(visitor); visitor.setUnreadCount(unread.size()); @@ -463,10 +462,10 @@ public class MessagesWWW { if (visitor.isAnonymous()) { return "redirect:/login"; } - visitor.setAvatar(webApp.getAvatarUrl(visitor)); + visitor.setAvatar(webApp.getAvatarWebPath(visitor)); String title = "PM: Inbox"; List<com.juick.Message> msgs = pmQueriesService.getLastPMInbox(visitor.getUid()); - msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarUrl(m.getUser()))); + msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarWebPath(m.getUser()))); fillUserModel(model, visitor, visitor); model.addAttribute("title", title); model.addAttribute("visitor", visitor); @@ -482,10 +481,10 @@ public class MessagesWWW { if (visitor.isAnonymous()) { return "redirect:/login"; } - visitor.setAvatar(webApp.getAvatarUrl(visitor)); + visitor.setAvatar(webApp.getAvatarWebPath(visitor)); String title = "PM: Sent"; List<com.juick.Message> msgs = pmQueriesService.getLastPMSent(visitor.getUid()); - msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarUrl(m.getUser()))); + msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarWebPath(m.getUser()))); if (WebUtils.isNotUserName(uname)) { uname = StringUtils.EMPTY; } @@ -508,7 +507,7 @@ public class MessagesWWW { if (!messagesService.canViewThread(mid, visitor.getUid())) { throw new HttpForbiddenException(); } - visitor.setAvatar(webApp.getAvatarUrl(visitor)); + visitor.setAvatar(webApp.getAvatarWebPath(visitor)); Optional<com.juick.Message> message = messagesService.getMessage(mid); if (!message.isPresent() || message.get().getUser().isBanned()) { @@ -522,7 +521,7 @@ public class MessagesWWW { return String.format("redirect:/%s/%d", msg.getUser().getName(), mid); } msg.VisitorCanComment = !visitor.isAnonymous(); - msg.getUser().setAvatar(webApp.getAvatarUrl(msg.getUser())); + msg.getUser().setAvatar(webApp.getAvatarWebPath(msg.getUser())); List<com.juick.Message> replies = messagesService.getReplies(visitor, msg.getMid()); // this should be after getReplies to mark thread as read fillUserModel(model, user, visitor); @@ -552,7 +551,7 @@ public class MessagesWWW { headers += "<meta property=\"og:image\" content=\"" + msgImage + "\" />"; } } else { - String msgImage ="https://i.juick.com/a/" + msg.getUser().getUid() + ".png"; + String msgImage = webApp.getAvatarPublicUrl(msg.getUser()); headers += "<meta property=\"og:image\" content=\"" + msgImage + "\" />"; } model.addAttribute("ogtype", "article"); @@ -582,7 +581,7 @@ public class MessagesWWW { blUIDs.add(reply.getUser().getUid()); } reply.VisitorCanComment = !visitor.isAnonymous(); - reply.getUser().setAvatar(webApp.getAvatarUrl(reply.getUser())); + reply.getUser().setAvatar(webApp.getAvatarWebPath(reply.getUser())); if (!visitor.isAnonymous()) { boolean isMsgAuthor = visitor.getUid() == msg.getUser().getUid(); boolean isReplyAuthor = visitor.getUid() == reply.getUser().getUid(); diff --git a/src/main/java/com/juick/server/www/controllers/NewMessage.java b/src/main/java/com/juick/server/www/controllers/NewMessage.java index 418d8805..1d3d2f5e 100644 --- a/src/main/java/com/juick/server/www/controllers/NewMessage.java +++ b/src/main/java/com/juick/server/www/controllers/NewMessage.java @@ -42,7 +42,7 @@ public class NewMessage { @GetMapping("/post") protected String postAction(@RequestParam(required = false) String body, ModelMap model) { com.juick.User visitor = UserUtils.getCurrentUser(); - visitor.setAvatar(webApp.getAvatarUrl(visitor)); + visitor.setAvatar(webApp.getAvatarWebPath(visitor)); model.addAttribute("title", "Написать"); model.addAttribute("headers", ""); model.addAttribute("visitor", visitor); diff --git a/src/main/java/com/juick/server/www/controllers/Settings.java b/src/main/java/com/juick/server/www/controllers/Settings.java index 82eb593a..03682586 100644 --- a/src/main/java/com/juick/server/www/controllers/Settings.java +++ b/src/main/java/com/juick/server/www/controllers/Settings.java @@ -87,7 +87,7 @@ public class Settings { if (visitor.isAnonymous()) { response.sendRedirect("/login"); } - visitor.setAvatar(webApp.getAvatarUrl(visitor)); + visitor.setAvatar(webApp.getAvatarWebPath(visitor)); List<String> pages = Arrays.asList("main", "password", "about", "auth-email", "privacy"); String page = request.getParameter("page"); if (StringUtils.isEmpty(page) || !pages.contains(page)) { diff --git a/src/main/java/com/juick/server/www/controllers/SignUp.java b/src/main/java/com/juick/server/www/controllers/SignUp.java index ee9c6703..eac1c767 100644 --- a/src/main/java/com/juick/server/www/controllers/SignUp.java +++ b/src/main/java/com/juick/server/www/controllers/SignUp.java @@ -87,7 +87,7 @@ public class SignUp { } model.addAttribute("title", "Новый пользователь"); - visitor.setAvatar(webApp.getAvatarUrl(visitor)); + visitor.setAvatar(webApp.getAvatarWebPath(visitor)); model.addAttribute("visitor", visitor); model.addAttribute("account", account); model.addAttribute("type", type); |