aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/www/controllers
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-11-20 15:16:08 +0300
committerGravatar Vitaly Takmazov2018-11-20 15:16:23 +0300
commitb0cfa955c77c4e36bd334324d0ccb2ff24ff549f (patch)
treec40954b3c453c7138514d1439fdcd6d969af0bec /src/main/java/com/juick/server/www/controllers
parent152efe1f31e1e568272fc401a3a19f2c6f7c9c49 (diff)
versioned avatars in www
Diffstat (limited to 'src/main/java/com/juick/server/www/controllers')
-rw-r--r--src/main/java/com/juick/server/www/controllers/Help.java5
-rw-r--r--src/main/java/com/juick/server/www/controllers/MessagesWWW.java27
-rw-r--r--src/main/java/com/juick/server/www/controllers/NewMessage.java4
-rw-r--r--src/main/java/com/juick/server/www/controllers/Settings.java4
-rw-r--r--src/main/java/com/juick/server/www/controllers/SignUp.java4
5 files changed, 38 insertions, 6 deletions
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 61b58a9d..e2a89bd6 100644
--- a/src/main/java/com/juick/server/www/controllers/Help.java
+++ b/src/main/java/com/juick/server/www/controllers/Help.java
@@ -19,6 +19,7 @@ package com.juick.server.www.controllers;
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.server.www.HelpService;
import org.commonmark.parser.Parser;
@@ -47,6 +48,8 @@ public class Help {
private Parser cmParser;
@Inject
private HtmlRenderer helpRenderer;
+ @Inject
+ private WebApp webApp;
@GetMapping({"/help/", "/help", "/help/{langOrPage}", "/help/{lang}/{page}"})
public String showHelp(
@@ -56,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));
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 77ee6e15..50d90555 100644
--- a/src/main/java/com/juick/server/www/controllers/MessagesWWW.java
+++ b/src/main/java/com/juick/server/www/controllers/MessagesWWW.java
@@ -24,6 +24,7 @@ import com.juick.server.util.HttpForbiddenException;
import com.juick.server.util.HttpNotFoundException;
import com.juick.server.util.UserUtils;
import com.juick.server.util.WebUtils;
+import com.juick.server.www.WebApp;
import com.juick.service.*;
import com.juick.util.MessageUtils;
import org.apache.commons.codec.CharEncoding;
@@ -68,9 +69,10 @@ public class MessagesWWW {
@Inject
private CrosspostService crosspostService;
@Inject
- private ApplicationEventPublisher applicationEventPublisher;
+ private WebApp webApp;
- void fillUserModel(ModelMap model, com.juick.User user, com.juick.User visitor) {
+ private void fillUserModel(ModelMap model, com.juick.User user, com.juick.User visitor) {
+ user.setAvatar(webApp.getAvatarUrl(user));
model.addAttribute("user", user);
model.addAttribute("isSubscribed", userService.isSubscribed(visitor.getUid(), user.getUid()));
model.addAttribute("isInBL", userService.isInBL(visitor.getUid(), user.getUid()));
@@ -100,6 +102,8 @@ public class MessagesWWW {
}
com.juick.User visitor = UserUtils.getCurrentUser();
+ visitor.setAvatar(webApp.getAvatarUrl(visitor));
+
if (paramSearch != null && paramSearch.length() > 64) {
paramSearch = null;
}
@@ -160,6 +164,7 @@ public class MessagesWWW {
List<Integer> blUIDs = userService.checkBL(visitor.getUid(),
msgs.stream().map(m -> m.getUser().getUid()).collect(Collectors.toList()));
msgs.forEach(m -> {
+ m.getUser().setAvatar(webApp.getAvatarUrl(m.getUser()));
m.ReadOnly |= blUIDs.contains(m.getUser().getUid());
m.setUnread(unread.contains(m.getMid()));
});
@@ -204,6 +209,7 @@ public class MessagesWWW {
if (user.isBanned() || user.isAnonymous()) {
throw new HttpNotFoundException();
}
+ visitor.setAvatar(webApp.getAvatarUrl(visitor));
List<Integer> mids;
@@ -277,6 +283,7 @@ public class MessagesWWW {
List<Integer> blUIDs = userService.checkBL(visitor.getUid(),
msgs.stream().map(m -> m.getUser().getUid()).collect(Collectors.toList()));
msgs.forEach(m -> {
+ m.getUser().setAvatar(webApp.getAvatarUrl(m.getUser()));
m.ReadOnly |= blUIDs.contains(m.getUser().getUid());
m.setUnread(unread.contains(m.getMid()));
});
@@ -315,6 +322,7 @@ public class MessagesWWW {
if (visitor.isBanned()) {
throw new HttpNotFoundException();
}
+ visitor.setAvatar(webApp.getAvatarUrl(visitor));
model.addAttribute("title", "Теги " + user.getName());
model.addAttribute("headers", "<meta name=\"robots\" content=\"noindex,nofollow\"/>");
@@ -333,6 +341,7 @@ public class MessagesWWW {
if (visitor.isBanned()) {
throw new HttpNotFoundException();
}
+ visitor.setAvatar(webApp.getAvatarUrl(visitor));
model.addAttribute("title", "Подписки " + user.getName());
model.addAttribute("headers", "<meta name=\"robots\" content=\"noindex\"/>");
model.addAttribute("visitor", visitor);
@@ -349,6 +358,7 @@ public class MessagesWWW {
if (visitor.isBanned()) {
throw new HttpForbiddenException();
}
+ visitor.setAvatar(webApp.getAvatarUrl(visitor));
model.addAttribute("title", "Читатели " + user.getName());
model.addAttribute("headers", "<meta name=\"robots\" content=\"noindex\"/>");
model.addAttribute("visitor", visitor);
@@ -365,6 +375,7 @@ public class MessagesWWW {
if (visitor.isBanned() || visitor.getUid() != user.getUid()) {
throw new HttpForbiddenException();
}
+ visitor.setAvatar(webApp.getAvatarUrl(visitor));
model.addAttribute("title", "Черный список " + user.getName());
model.addAttribute("headers", "<meta name=\"robots\" content=\"noindex\"/>");
model.addAttribute("visitor", visitor);
@@ -380,7 +391,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));
String paramTagStr = StringEscapeUtils.unescapeHtml4(tagName);
com.juick.Tag paramTag = tagService.getTag(paramTagStr, false);
if (paramTag == null) {
@@ -412,6 +423,7 @@ public class MessagesWWW {
msgs.stream().map(m -> m.getUser().getUid()).collect(Collectors.toList())
);
msgs.forEach(m -> {
+ m.getUser().setAvatar(webApp.getAvatarUrl(m.getUser()));
m.ReadOnly |= blUIDs.contains(m.getUser().getUid());
m.setUnread(unread.contains(m.getMid()));
});
@@ -453,8 +465,10 @@ public class MessagesWWW {
if (visitor.isAnonymous()) {
return "redirect:/login";
}
+ visitor.setAvatar(webApp.getAvatarUrl(visitor));
String title = "PM: Inbox";
List<com.juick.Message> msgs = pmQueriesService.getLastPMInbox(visitor.getUid());
+ msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarUrl(m.getUser())));
fillUserModel(model, visitor, visitor);
model.addAttribute("title", title);
model.addAttribute("visitor", visitor);
@@ -470,9 +484,10 @@ public class MessagesWWW {
if (visitor.isAnonymous()) {
return "redirect:/login";
}
+ visitor.setAvatar(webApp.getAvatarUrl(visitor));
String title = "PM: Sent";
List<com.juick.Message> msgs = pmQueriesService.getLastPMSent(visitor.getUid());
-
+ msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarUrl(m.getUser())));
if (WebUtils.isNotUserName(uname)) {
uname = StringUtils.EMPTY;
}
@@ -495,7 +510,7 @@ public class MessagesWWW {
if (!messagesService.canViewThread(mid, visitor.getUid())) {
throw new HttpForbiddenException();
}
-
+ visitor.setAvatar(webApp.getAvatarUrl(visitor));
Optional<com.juick.Message> message = messagesService.getMessage(mid);
if (!message.isPresent() || message.get().getUser().isBanned()) {
@@ -517,6 +532,7 @@ public class MessagesWWW {
visitor.setUnreadCount(unread.size());
boolean isMsgAuthor = visitor.getUid() == msg.getUser().getUid();
boolean isInBL = userService.isInBLAny(msg.getUser().getUid(), visitor.getUid());
+ msg.getUser().setAvatar(webApp.getAvatarUrl(msg.getUser()));
msg.VisitorCanComment = isMsgAuthor || !(msg.ReadOnly || isInBL);
}
model.addAttribute("msg", msg);
@@ -571,6 +587,7 @@ public class MessagesWWW {
if (!visitor.isAnonymous()) {
boolean isMsgAuthor = visitor.getUid() == msg.getUser().getUid();
boolean isReplyAuthor = visitor.getUid() == reply.getUser().getUid();
+ reply.getUser().setAvatar(webApp.getAvatarUrl(reply.getUser()));
reply.VisitorCanComment = isMsgAuthor || (!msg.ReadOnly
&& msg.VisitorCanComment && (isReplyAuthor || !userService.isInBLAny(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 6b5938a5..418d8805 100644
--- a/src/main/java/com/juick/server/www/controllers/NewMessage.java
+++ b/src/main/java/com/juick/server/www/controllers/NewMessage.java
@@ -17,6 +17,7 @@
package com.juick.server.www.controllers;
import com.juick.server.util.UserUtils;
+import com.juick.server.www.WebApp;
import com.juick.service.TagService;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
@@ -36,9 +37,12 @@ public class NewMessage {
@Inject
private TagService tagService;
+ @Inject
+ private WebApp webApp;
@GetMapping("/post")
protected String postAction(@RequestParam(required = false) String body, ModelMap model) {
com.juick.User visitor = UserUtils.getCurrentUser();
+ visitor.setAvatar(webApp.getAvatarUrl(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 cc8f43eb..82eb593a 100644
--- a/src/main/java/com/juick/server/www/controllers/Settings.java
+++ b/src/main/java/com/juick/server/www/controllers/Settings.java
@@ -22,6 +22,7 @@ import com.juick.model.UserInfo;
import com.juick.server.util.HttpBadRequestException;
import com.juick.server.util.HttpUtils;
import com.juick.server.util.UserUtils;
+import com.juick.server.www.WebApp;
import com.juick.service.*;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
@@ -77,6 +78,8 @@ public class Settings {
private TelegramService telegramService;
@Inject
private ImagesService imagesService;
+ @Inject
+ private WebApp webApp;
@GetMapping("/settings")
protected String doGet(HttpServletRequest request, HttpServletResponse response, ModelMap model) throws IOException {
@@ -84,6 +87,7 @@ public class Settings {
if (visitor.isAnonymous()) {
response.sendRedirect("/login");
}
+ visitor.setAvatar(webApp.getAvatarUrl(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 6a4fe063..ee9c6703 100644
--- a/src/main/java/com/juick/server/www/controllers/SignUp.java
+++ b/src/main/java/com/juick/server/www/controllers/SignUp.java
@@ -19,6 +19,7 @@ package com.juick.server.www.controllers;
import com.juick.server.util.HttpBadRequestException;
import com.juick.server.util.HttpForbiddenException;
import com.juick.server.util.UserUtils;
+import com.juick.server.www.WebApp;
import com.juick.service.CrosspostService;
import com.juick.service.EmailService;
import com.juick.service.MessengerService;
@@ -48,6 +49,8 @@ public class SignUp {
private MessengerService messengerService;
@Inject
private EmailService emailService;
+ @Inject
+ private WebApp webApp;
@GetMapping("/signup")
@@ -84,6 +87,7 @@ public class SignUp {
}
model.addAttribute("title", "Новый пользователь");
+ visitor.setAvatar(webApp.getAvatarUrl(visitor));
model.addAttribute("visitor", visitor);
model.addAttribute("account", account);
model.addAttribute("type", type);