aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/java/com/juick/www/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'juick-www/src/main/java/com/juick/www/controllers')
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/Messages.java95
1 files changed, 57 insertions, 38 deletions
diff --git a/juick-www/src/main/java/com/juick/www/controllers/Messages.java b/juick-www/src/main/java/com/juick/www/controllers/Messages.java
index 2af6c21a..381faf34 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/Messages.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/Messages.java
@@ -18,12 +18,14 @@ package com.juick.www.controllers;
import com.juick.Tag;
import com.juick.formatters.PlainTextFormatter;
+import com.juick.server.helpers.TagStats;
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.service.*;
import com.juick.www.Utils;
+import com.mitchellbosecke.pebble.extension.i18n.UTF8Control;
import org.apache.commons.codec.CharEncoding;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
@@ -42,7 +44,10 @@ import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.List;
+import java.util.Locale;
+import java.util.ResourceBundle;
import java.util.function.BooleanSupplier;
import java.util.stream.Collectors;
@@ -59,6 +64,8 @@ public class Messages {
@Inject
private MessagesService messagesService;
@Inject
+ private SubscriptionService subscriptionService;
+ @Inject
private Sape sape;
@Inject
private PMQueriesService pmQueriesService;
@@ -75,9 +82,17 @@ public class Messages {
model.addAttribute("statsMyBL", userService.getUserBLUsers(user.getUid()).size());
model.addAttribute("statsMessages", userService.getStatsMessages(user.getUid()));
model.addAttribute("statsReplies", userService.getStatsReplies(user.getUid()));
+ model.addAttribute("statsPhotos", userService.getStatsPhotos(user.getUid()));
+ model.addAttribute("statsFavorites", userService.getStatsFavorites(user.getUid()));
model.addAttribute("iread", userService.getUserReadLeastPopular(user.getUid(), 8));
- model.addAttribute("tagStats", tagService.getUserTagStats(user.getUid())
- .stream().sorted((e1, e2) -> Integer.compare(e2.getUsageCount(), e1.getUsageCount())).limit(20).map(t -> t.getTag().getName()).collect(Collectors.toList()));
+ model.addAttribute("tagStats",
+ tagService.getUserTagStats(user.getUid())
+ .stream()
+ .sorted(Comparator.comparing(TagStats::getUsageCount).reversed())
+ .limit(20)
+ .map(t -> t.getTag().getName())
+ .collect(Collectors.toList())
+ );
}
@GetMapping("/{anything}/**")
@@ -118,76 +133,82 @@ public class Messages {
@RequestParam(name = "search", required = false) String paramSearch,
@RequestParam(name = "before", required = false, defaultValue = "0") Integer paramBefore,
@CookieValue(name = "sape_cookie", required = false, defaultValue = StringUtils.EMPTY) String sapeCookie,
- ModelMap model) throws IOException {
+ ModelMap model,
+ Locale locale) throws IOException {
if (tag != null) {
return "redirect:/tag/" + URLEncoder.encode(tag, CharEncoding.UTF_8);
}
- com.juick.User visitor = UserUtils.getCurrentUser();
-
if (paramSearch != null && paramSearch.length() > 64) {
paramSearch = null;
}
+ ResourceBundle messagesBundle = ResourceBundle.getBundle("messages", locale, new UTF8Control());
+ com.juick.User visitor = UserUtils.getCurrentUser();
+
String title;
List<Integer> mids;
-
if (paramSearch != null) {
- title = "Поиск: " + StringEscapeUtils.escapeHtml4(paramSearch);
+ title = messagesBundle.getString("label.search") + ": " +
+ StringEscapeUtils.escapeHtml4(paramSearch);
mids = messagesService.getSearch(Utils.encodeSphinx(paramSearch), paramBefore);
} else if (paramShow == null) {
if (visitor.getUid() > 0) {
- title = "Популярные";
+ title = messagesBundle.getString("title.index.user");
mids = messagesService.getPopular(visitor.getUid(), paramBefore);
} else {
- title = "Микроблоги Juick: популярные записи";
+ title = messagesBundle.getString("title.index.anonym");
mids = messagesService.getPopular(0, paramBefore);
}
-
} else if (paramShow.equals("top")) {
return "redirect:/";
} else if (paramShow.equals("my") && !visitor.isAnonymous()) {
- title = "Моя лента";
+ title = messagesBundle.getString("link.my");
mids = messagesService.getMyFeed(visitor.getUid(), paramBefore, true);
} else if (paramShow.equals("private") && !visitor.isAnonymous()) {
- title = "Приватные";
+ title = messagesBundle.getString("link.privateMessages");
mids = messagesService.getPrivate(visitor.getUid(), paramBefore);
} else if (paramShow.equals("discuss") && !visitor.isAnonymous()) {
- title = "Обсуждения";
+ title = messagesBundle.getString("link.discuss");
mids = messagesService.getDiscussions(visitor.getUid(), paramBefore);
} else if (paramShow.equals("recommended") && !visitor.isAnonymous()) {
- title = "Рекомендации";
+ title = messagesBundle.getString("link.recommended");
mids = messagesService.getRecommended(visitor.getUid(), paramBefore);
} else if (paramShow.equals("photos")) {
- title = "Фотографии";
+ title = messagesBundle.getString("link.withPhotos");
mids = messagesService.getPhotos(visitor.getUid(), paramBefore);
} else if (paramShow.equals("all")) {
- title = "Все сообщения";
+ title = messagesBundle.getString("link.allMessages");
mids = messagesService.getAll(visitor.getUid(), paramBefore);
} else {
throw new HttpNotFoundException();
}
+ List<com.juick.Message> msgs = messagesService.getMessages(mids);
+ if (visitor.getUid() != 0) {
+ List<Integer> blUIDs = userService.checkBL(
+ visitor.getUid(),
+ msgs.stream().map(m -> m.getUser().getUid()).collect(Collectors.toList())
+ );
+ msgs.forEach(m -> m.ReadOnly |= blUIDs.contains(m.getUser().getUid()));
+ fillUserModel(model, visitor, visitor);
+ }
+
String head = StringUtils.EMPTY;
if (paramBefore > 0 || paramShow != null) {
head = "<meta name=\"robots\" content=\"noindex\"/>";
}
+ model.addAttribute("paramShow", !StringUtils.isEmpty(paramShow)
+ ? paramShow
+ : ((paramSearch != null) ? "search" : "top"));
model.addAttribute("title", title);
model.addAttribute("headers", head);
model.addAttribute("visitor", visitor);
model.addAttribute("noindex", !(paramShow == null && paramBefore == 0));
- List<com.juick.Message> msgs = messagesService.getMessages(mids);
-
- if (visitor.getUid() != 0) {
- fillUserModel(model, visitor, visitor);
- List<Integer> blUIDs = userService.checkBL(visitor.getUid(),
- msgs.stream().map(m -> m.getUser().getUid()).collect(Collectors.toList()));
- msgs.forEach(m -> m.ReadOnly |= blUIDs.contains(m.getUser().getUid()));
- }
model.addAttribute("msgs", msgs);
- model.addAttribute("tags", tagService.getPopularTags());
- model.addAttribute("headers", head);
- model.addAttribute("showAdv",
- paramShow == null && paramBefore == 0 && paramSearch == null && visitor.getUid() == 0);
+ model.addAttribute("tags", (visitor.getUid() != 0)
+ ? subscriptionService.getSubscribedTags(visitor)
+ : tagService.getPopularTags());
+ model.addAttribute("showAdv", paramShow == null && paramBefore == 0 && paramSearch == null && visitor.getUid() == 0);
if (mids.size() >= 20) {
String nextpage = "?before=" + mids.get(mids.size() - 1);
if (paramShow != null) {
@@ -370,21 +391,21 @@ public class Messages {
return "views/users";
}
- @GetMapping("/{uname}/bl")
- protected String doGetBL(@PathVariable String uname, ModelMap model) throws IOException {
- com.juick.User user = userService.getUserByName(uname);
+ @GetMapping("/bl")
+ protected String doGetBL(ModelMap model) throws IOException {
com.juick.User visitor = UserUtils.getCurrentUser();
- if (visitor.isBanned() || visitor.getUid() != user.getUid()) {
+ if (visitor.isBanned()) {
throw new HttpForbiddenException();
}
- model.addAttribute("title", "Черный список " + user.getName());
+ model.addAttribute("title", "Черный список " + visitor.getName());
model.addAttribute("headers", "<meta name=\"robots\" content=\"noindex\"/>");
model.addAttribute("visitor", visitor);
- fillUserModel(model, user, visitor);
- model.addAttribute("users", userService.getUserBLUsers(user.getUid()));
+ fillUserModel(model, visitor, visitor);
+ model.addAttribute("users", userService.getUserBLUsers(visitor.getUid()));
return "views/users";
}
+
@GetMapping("/tag/{tagName}")
protected String tagAction(HttpServletRequest request,
@PathVariable String tagName,
@@ -413,8 +434,6 @@ public class Messages {
int visitor_uid = visitor.getUid();
- String title = "*" + StringEscapeUtils.escapeHtml4(paramTag.getName());
- model.addAttribute("title", title);
List<Integer> mids = messagesService.getTag(paramTag.TID, visitor_uid, before, (visitor_uid == 0) ? 40 : 20);
List<com.juick.Message> msgs = messagesService.getMessages(mids);
if (visitor.getUid() != 0) {
@@ -435,7 +454,7 @@ public class Messages {
model.addAttribute("headers", head);
model.addAttribute("visitor", visitor);
model.addAttribute("tag", paramTag);
- model.addAttribute("title", title);
+ model.addAttribute("title", "*" + StringEscapeUtils.escapeHtml4(paramTag.getName()));
model.addAttribute("msgs", msgs);
model.addAttribute("tags", tagService.getPopularTags());
model.addAttribute("noindex", before > 0);