From ebfae6637d88c9d444f39c7fbe43ce4b7ffc130f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 20 Dec 2016 15:28:54 +0300 Subject: juick-spring-www: WIP --- .../juick/www/controllers/ThreadController.java | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 juick-spring-www/src/main/java/com/juick/www/controllers/ThreadController.java (limited to 'juick-spring-www/src/main/java/com/juick/www/controllers/ThreadController.java') 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 = ""; + if (paramView != null) { + headers += ""; + } + if (msg.Hidden) { + headers += ""; + } + modelMap.put("headers", headers); + modelMap.put("msg", msg); + modelMap.put("listview", listview); + return "views/thread"; + } +} -- cgit v1.2.3