Map<String, Object> params = new HashMap<>();
List<TagRef> tags = topicTagService.getTagRefs(topic);
MessageText messageText = msgbaseDao.getMessageText(topic.getId());
String plainText = lorCodeService.extractPlainText(messageText);
Future<List<List<MoreLikeThisTopic>>> moreLikeThis = moreLikeThisService.search(topic, tags, plainText);
PreparedTopic preparedMessage = messagePrepareService.prepareTopic(
topic,
tags,
request.isSecure(),
tmpl.getCurrentUser(),
messageText
);
Group group = preparedMessage.getGroup();
if (!group.getUrlName().equals(groupName) || group.getSectionId() != section.getId()) {
return new ModelAndView(new RedirectView(topic.getLink()));
}
boolean showDeleted = request.getParameter("deleted") != null;
if (showDeleted) {
page = -1;
}
if (!tmpl.isModeratorSession()) {
if (showDeleted && !"POST".equals(request.getMethod())) {
return new ModelAndView(new RedirectView(topic.getLink()));
}
}
if (page == -1 && !showDeleted) {
return new ModelAndView(new RedirectView(topic.getLink()));
}
int pages = topic.getPageCount(tmpl.getProf().getMessages());
if (page >= pages && (page > 0 || pages > 0)) {
if (pages==0) {
return new ModelAndView(new RedirectView(topic.getLink()));
} else {
return new ModelAndView(new RedirectView(topic.getLinkPage(pages - 1)));
}
}
if (showDeleted) {
if (!tmpl.isSessionAuthorized()) {
throw new BadInputException("Вы уже вышли из системы");
}
}
params.put("showDeleted", showDeleted);
User currentUser = AuthUtil.getCurrentUser();
permissionService.checkView(group, topic, currentUser, showDeleted);
params.put("message", topic);
params.put("preparedMessage", preparedMessage);
if (topic.isExpired()) {
response.setDateHeader("Expires", System.currentTimeMillis() + 30 * 24 * 60 * 60 * 1000L);
}
CommentList comments = commentService.getCommentList(topic, showDeleted);
if (messageText.isLorcode()) {
params.put("ogDescription", lorCodeService.trimPlainText(plainText, 250, true));
}
params.put("page", page);
params.put("group", group);