if (comment.isDeleted()) {
throw new UserErrorException("комментарий уже удален");
}
Topic topic = messageDao.getById(comment.getTopicId());
final boolean haveAnswers = commentService.isHaveAnswers(comment);
if (!permissionService.isCommentDeletableNow(comment, user, topic, haveAnswers)) {
throw new UserErrorException("комментарий нельзя удалить");
}
if (!user.isModerator() || comment.getUserid() == user.getId()) {
bonus = 0;
}
List<Integer> deleted;
if (user.isModerator()) {
deleted = commentService.deleteWithReplys(topic, comment, reason, user, bonus);
} else {
if (commentService.deleteComment(msgid, reason, user)) {
deleted = ImmutableList.of(msgid);
} else {
deleted = ImmutableList.of();
}
}
Optional<Comment> nextComment = findNextComment(comment);
searchQueueSender.updateComment(deleted);
Map<String, Object> params = new HashMap<>();
if (!deleted.isEmpty()) {
params.put("message", "Удалено успешно");
params.put("bigMessage", "Удаленные комментарии: "+deleted);
} else {
params.put("message", "Сообщение уже удалено");
}
if (nextComment.isPresent()) {
params.put("link", topic.getLink()+"?cid="+nextComment.get().getId()+"&lastmod=");
} else {
params.put("link", topic.getLink());
}
return new ModelAndView("action-done", params);
}