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";
}
}