aboutsummaryrefslogtreecommitdiff
path: root/juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java')
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java86
1 files changed, 80 insertions, 6 deletions
diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java
index 5c3b6287..0961f683 100644
--- a/juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java
+++ b/juick-spring-www/src/main/java/com/juick/www/controllers/TagController.java
@@ -1,14 +1,28 @@
package com.juick.www.controllers;
+import com.juick.Message;
+import com.juick.User;
+import com.juick.server.util.HttpNotFoundException;
+import com.juick.service.AdsService;
import com.juick.service.MessagesService;
import com.juick.service.TagService;
+import com.juick.service.UserService;
+import com.juick.util.UserUtils;
+import com.juick.www.helpers.QueryString;
+import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.stereotype.Controller;
-import org.springframework.ui.Model;
+import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.inject.Inject;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.security.Principal;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
/**
* Created by aalexeev on 11/21/16.
@@ -19,15 +33,75 @@ public class TagController {
private TagService tagService;
@Inject
private MessagesService messagesService;
+ @Inject
+ private AdsService adsService;
+ @Inject
+ private UserService userService;
@RequestMapping("/tag/{tagName}")
- public String showTags(
- @PathVariable String tagName,
- @RequestParam(required = false, defaultValue = "0") int before,
- Model model) {
+ protected String doGet(
+ Principal principal,
+ @PathVariable("tagName") String paramTagStr,
+ @RequestParam(value = "before", required = false, defaultValue = "0") Integer paramBefore,
+ @QueryString Optional<String> queryString,
+ ModelMap model) throws UnsupportedEncodingException {
+ String name = UserUtils.getUsername(principal, null);
+ User visitor = userService.getUserByName(name);
+
+ com.juick.Tag paramTag = tagService.getTag(paramTagStr, false);
+ if (paramTag == null) {
+ throw new HttpNotFoundException();
+ } else if (paramTag.SynonymID > 0 && paramTag.TID != paramTag.SynonymID) {
+ com.juick.Tag synTag = tagService.getTag(paramTag.SynonymID);
+ String url = "/tag/" + URLEncoder.encode(synTag.getName(), "UTF-8");
+ if (queryString.isPresent()) {
+ url += "?" + queryString.get();
+ }
+ return "redirect:" + url;
+ } else if (!paramTag.getName().equals(paramTagStr)) {
+ String url = "/tag/" + URLEncoder.encode(paramTag.getName(), "UTF-8");
+ if (queryString.isPresent()) {
+ url += "?" + queryString.get();
+ }
+ return "redirect:" + url;
+ }
+
+ int visitor_uid = visitor != null ? visitor.getUid() : 0;
- return "index";
+ String title = "*" + StringEscapeUtils.escapeHtml4(paramTag.getName());
+ List<Integer> mids = messagesService.getTag(paramTag.TID, visitor_uid, paramBefore, (visitor == null) ? 40 : 20);
+ model.addAttribute("title", title);
+ if (tagService.getTagNoIndex(paramTag.TID)) {
+ model.addAttribute("headers", "<meta name=\"robots\" content=\"noindex,nofollow\"/>");
+ } else if (paramBefore > 0 || mids.size() < 5) {
+ model.addAttribute("headers", "<meta name=\"robots\" content=\"noindex\"/>");
+ }
+ if (mids.size() > 0) {
+ int vuid = visitor != null ? visitor.getUid() : 0;
+ int ad_mid = adsService.getAdMid(vuid);
+ if (ad_mid > 0 && mids.indexOf(ad_mid) == -1) {
+ mids.add(0, ad_mid);
+ adsService.logAdMid(vuid, ad_mid);
+ } else {
+ ad_mid = 0;
+ }
+ }
+ model.addAttribute("visitor", visitor);
+ List<Message> msgs = messagesService.getMessages(mids);
+ List<Integer> blUIDs = userService.checkBL(visitor_uid,
+ msgs.stream().map(m -> m.getUser().getUid()).collect(Collectors.toList()));
+ model.addAttribute("msgs",
+ msgs.stream().map(msg -> {
+ msg.ReadOnly |= blUIDs.contains(msg.getUser().getUid());
+ return msg;
+ }).collect(Collectors.toList())
+ );
+ if (mids.size() >= 20) {
+ String nextpage = "/tag/" + URLEncoder.encode(paramTag.getName(), "UTF-8") + "?before=" + mids.get(mids.size() - 1);
+ model.addAttribute("nextpage", nextpage);
+ }
+ return "blog/index";
}
@RequestMapping("/tag")