diff options
author | Vitaly Takmazov | 2016-12-20 15:28:54 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-12-20 15:28:54 +0300 |
commit | ebfae6637d88c9d444f39c7fbe43ce4b7ffc130f (patch) | |
tree | 5d65fb9e9c7a6d96c210997c0425c43a9a68fa5c /juick-spring-www/src/main/java/com/juick/www | |
parent | 3859c9616d0a7a04e68427d173b863161b818140 (diff) |
juick-spring-www: WIP
Diffstat (limited to 'juick-spring-www/src/main/java/com/juick/www')
3 files changed, 84 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"; + } +} |