aboutsummaryrefslogtreecommitdiff
path: root/juick-spring-www/src
diff options
context:
space:
mode:
Diffstat (limited to 'juick-spring-www/src')
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java20
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java22
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/ThreadController.java67
-rw-r--r--juick-spring-www/src/main/webapp/WEB-INF/templates/views/partial/thread_message.html57
-rw-r--r--juick-spring-www/src/main/webapp/WEB-INF/templates/views/thread.html17
5 files changed, 158 insertions, 25 deletions
diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java
index 54d83b61..87540795 100644
--- a/juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java
+++ b/juick-spring-www/src/main/java/com/juick/www/controllers/IndexController.java
@@ -7,7 +7,6 @@ import com.juick.service.TagService;
import com.juick.service.UserService;
import com.juick.util.UserUtils;
import com.juick.www.util.EncodeUtils;
-import org.apache.commons.lang3.CharEncoding;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.MessageSource;
@@ -20,7 +19,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import javax.inject.Inject;
import java.io.IOException;
-import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@@ -48,17 +46,23 @@ public class IndexController {
@RequestParam(value = "search", required = false) String paramSearch,
ModelMap model) throws IOException {
- if (paramTagStr.isPresent())
- return "redirect:/tag/" + URLEncoder.encode(paramTagStr.get(), CharEncoding.UTF_8);
+ int before = paramBefore.orElse(0);
+ String tag = paramTagStr.orElse(StringUtils.EMPTY);
+
+ if (StringUtils.isNotEmpty(tag)) {
+ StringBuilder builder = new StringBuilder();
+ builder.append("redirect:").append("/tag/").append(tag);
+ if (before > 0)
+ builder.append("?before=").append(before);
+ return builder.toString();
+ }
if (StringUtils.isNotEmpty(paramSearch) && paramSearch.length() > 64)
- paramSearch = "";
+ paramSearch = StringUtils.EMPTY;
User visitor = UserUtils.getCurrentUser();
- String title = "";
-
- int before = paramBefore.orElse(0);
+ String title = StringUtils.EMPTY;
List<Integer> mids = new ArrayList<>();
diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java
index 406c27ed..93039a37 100644
--- a/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java
+++ b/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java
@@ -30,20 +30,8 @@ public class ShowMessageController {
public String parseAnything(
@PathVariable String anything,
@RequestParam(required = false, defaultValue = "0") int before,
- @RequestParam(required = false) String tag,
Model model) {
- if (StringUtils.isNotEmpty(tag)) {
- StringBuilder builder = new StringBuilder();
-
- builder.append("redirect:/").append(anything).append("/tag/").append(tag);
-
- if (before > 0)
- builder.append("?before=").append(before);
-
- return builder.toString();
- }
-
if (before == 0) {
boolean isPostNumber = WebUtils.isPostNumber(anything);
int messageId = isPostNumber ?
@@ -65,7 +53,7 @@ public class ShowMessageController {
return showUserMessages(anything, null, before, model);
}
- @RequestMapping("/{userName}/tag/{tagName}")
+ //@RequestMapping("/{userName}/tag/{tagName}")
public String showUserMessagesByTag(
@PathVariable String userName,
@PathVariable String tagName,
@@ -95,7 +83,7 @@ public class ShowMessageController {
return "views/index";
}
- @RequestMapping("/{userName}/friends")
+ //@RequestMapping("/{userName}/friends")
public String getFriends(
@PathVariable String userName,
Model model) {
@@ -114,7 +102,7 @@ public class ShowMessageController {
return "views/index";
}
- @RequestMapping("/{userName}/readers")
+ //@RequestMapping("/{userName}/readers")
public String getReaders(
@PathVariable String userName,
Model model) {
@@ -152,7 +140,7 @@ public class ShowMessageController {
return "views/index";
}
- @RequestMapping("/{userName}/{postNumber}")
+ //@RequestMapping("/{userName}/{postNumber}")
public String checkShowPost(
@PathVariable String userName,
@PathVariable String postNumber,
@@ -176,6 +164,6 @@ public class ShowMessageController {
}
- return "index";
+ return "views/thread";
}
}
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";
+ }
+}
diff --git a/juick-spring-www/src/main/webapp/WEB-INF/templates/views/partial/thread_message.html b/juick-spring-www/src/main/webapp/WEB-INF/templates/views/partial/thread_message.html
new file mode 100644
index 00000000..159eebf5
--- /dev/null
+++ b/juick-spring-www/src/main/webapp/WEB-INF/templates/views/partial/thread_message.html
@@ -0,0 +1,57 @@
+<ul xmlns:th="http://www.thymeleaf.org">
+ <li th:id="|msg-${msg.getMid()}|" th:data-mid="${msg.getMid()}" class="msg msgthread">
+ <div class="msg-cont">
+ <div class="msg-menu"><a href="#"></a></div>
+ <div class="msg-ts" th:text="${msg.getDate()}">01.01.1970</div>
+ <div class="msg-avatar">
+ <a th:href="|/${msg.getUser().getName()}/|">
+ <img th:src="|//i.juick.com/a/${msg.getUser().getUid()}.png|"
+ th:alt="${msg.getUser().getName()}"/>
+ </a>
+ </div>
+ <div class="msg-header">
+ @<a th:href="|/${msg.getUser().getName()}/|" th:text="${msg.getUser().getName()}">ugnich</a>:
+ <th:block th:text="${tagsStr}"/>
+ </div>
+ <div class="msg-txt" th:utext="${msg.getText()}">
+ Lorem ipsum
+ </div>
+ <div class="msg-media" th:if="${msg.getAttachmentType() != null}">
+ <a href="|//i.juick.com/p/${msg.getMid()}.${msg.getAttachmentType()}|">
+ <img src="|//i.juick.com/photos-512/${msg.getMid()}.${msg.getAttachmentType()}|"/>
+ </a>
+ </div>
+ <form th:if="${msg.VisitorCanComment}" action="/comment" method="POST" enctype="multipart/form-data">
+ <input type="hidden" name="mid" th:value="${msg.getMid()}"/>
+ <div class="msg-comment">
+ <div class="ta-wrapper">
+ <textarea name="body" rows="1" class="reply" placeholder="Написать комментарий"></textarea>
+ </div>
+ </div>
+ </form>
+ <div class="msg-recomms" th:text="|Рекомендовали (${recommsCount}): ${recomms}|">Recommended(1): @ugnich</div>
+ </div>
+ </li>
+ <li id="mtoolbar">
+ <ul>
+ <li><a th:href="|/${msg.getMid()}|">
+ <div style="background-position: -64px 0"></div>
+ <th:block th:text="${msg.getMid()}"></th:block>
+ </a></li>
+ <th:block th:if="${#authorization.expression('isAuthenticated()')}">
+ <li th:if="${isSubscribed}"><a th:href="|/post?body=U+%23${msg.getMid()}|">
+ <div style="background-position: -48px 0"></div>
+ Подписан</a></li>
+ <li th:if="${isSubscribed == false}"><a th:href="|/post?body=S+%23${msg.getMid()}|">
+ <div style="background-position: -16px 0"></div>
+ Подписаться</a></li>
+ <li th:if="${visitorInBL == false}"><a th:href="|/post?body=%21+%23${msg.getMid()}|">
+ <div style="background-position: -32px 0"></div>
+ Рекомендовать</a></li>
+ <li th:if="${isOwnMessage}"><a th:href="|/post?body=D+%23${msg.getMid()}|">
+ <div style="background-position: 0"></div>
+ Удалить</a></li>
+ </th:block>
+ </ul>
+ </li>
+</ul> \ No newline at end of file
diff --git a/juick-spring-www/src/main/webapp/WEB-INF/templates/views/thread.html b/juick-spring-www/src/main/webapp/WEB-INF/templates/views/thread.html
new file mode 100644
index 00000000..ac7da17f
--- /dev/null
+++ b/juick-spring-www/src/main/webapp/WEB-INF/templates/views/thread.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html xmlns:th="http://www.thymeleaf.org"
+ xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
+ layout:decorate="~{layout/mainLayout}">
+<head>
+ <title th:if="${#authorization.expression('isAuthenticated()')}" th:text="${title}">Page title</title>
+</head>
+
+<body>
+<section id="content" th:data-mid="${mid}" style="margin-left: 0; width: 100%">
+ <th:block layout:fragment="content">
+ <th:block th:replace="views/partial/thread_message"/>
+ </th:block>
+</section>
+</body>
+</html>
+