aboutsummaryrefslogtreecommitdiff
path: root/juick-spring-www/src/main/java/com/juick/www/controllers/ThreadController.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-spring-www/src/main/java/com/juick/www/controllers/ThreadController.java')
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/ThreadController.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/ThreadController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/ThreadController.java
new file mode 100644
index 00000000..f8693e13
--- /dev/null
+++ b/juick-spring-www/src/main/java/com/juick/www/controllers/ThreadController.java
@@ -0,0 +1,67 @@
+package com.juick.www.controllers;
+
+import com.juick.server.util.HttpForbiddenException;
+import com.juick.service.MessagesService;
+import com.juick.service.UserService;
+import com.juick.util.UserUtils;
+import org.springframework.stereotype.Controller;
+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;
+
+/**
+ * Created by vitalyster on 20.12.2016.
+ */
+@Controller
+public class ThreadController {
+ @Inject
+ MessagesService messagesService;
+ @Inject
+ UserService userService;
+
+ @RequestMapping(value = "/{userName}/{mid}")
+ public String doGetThread(
+ @PathVariable int mid,
+ @RequestParam(required = false, value = "view") String paramView,
+ ModelMap modelMap) {
+ com.juick.User visitor = UserUtils.getCurrentUser();
+
+ if (!messagesService.canViewThread(mid, visitor.getUid())) {
+ throw new HttpForbiddenException();
+ }
+
+ com.juick.Message msg = messagesService.getMessage(mid);
+
+ boolean listview = false;
+ if (paramView != null) {
+ if (paramView.equals("list")) {
+ listview = true;
+ if (visitor.getUid() > 0) {
+ userService.setUserOptionInt(visitor.getUid(), "repliesview", 1);
+ }
+ } else if (paramView.equals("tree") && visitor.getUid() > 0) {
+ userService.setUserOptionInt(visitor.getUid(), "repliesview", 0);
+ }
+ } else if (visitor.getUid() > 0 && userService.getUserOptionInt(visitor.getUid(), "repliesview", 0) == 1) {
+ listview = true;
+ }
+
+ String title = msg.getUser().getName() + ": " + msg.getTagsString();
+
+ modelMap.put("title", title);
+ String headers = "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"@" + msg.getUser().getName() + "\" href=\"//rss.juick.com/" + msg.getUser().getName() + "/blog\"/>";
+ if (paramView != null) {
+ headers += "<link rel=\"canonical\" href=\"http://juick.com/" + msg.getUser().getName() + "/" + msg.getMid() + "\"/>";
+ }
+ if (msg.Hidden) {
+ headers += "<meta name=\"robots\" content=\"noindex\"/>";
+ }
+ modelMap.put("headers", headers);
+ modelMap.put("msg", msg);
+ modelMap.put("listview", listview);
+ return "views/thread";
+ }
+}