mirror of https://github.com/halo-dev/halo
✨ 可选是否显示未审核的评论
parent
6da6c21478
commit
da6ffd600d
|
@ -71,6 +71,11 @@ public enum BlogProperties {
|
||||||
*/
|
*/
|
||||||
COMMENT_REPLY_NOTICE("comment_reply_notice"),
|
COMMENT_REPLY_NOTICE("comment_reply_notice"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新评论是否需要审核
|
||||||
|
*/
|
||||||
|
NEW_COMMENT_NEED_CHECK("new_comment_need_check"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新评论通知
|
* 新评论通知
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -64,6 +64,15 @@ public interface CommentRepository extends JpaRepository<Comment, Long> {
|
||||||
*/
|
*/
|
||||||
List<Comment> findCommentsByPostAndCommentStatus(Post post, Integer status);
|
List<Comment> findCommentsByPostAndCommentStatus(Post post, Integer status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据文章和评论状态(为不查询的)查询评论 不分页
|
||||||
|
*
|
||||||
|
* @param post post
|
||||||
|
* @param status status
|
||||||
|
* @return List
|
||||||
|
*/
|
||||||
|
List<Comment> findCommentsByPostAndCommentStatusNot(Post post, Integer status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询最新的前五条评论
|
* 查询最新的前五条评论
|
||||||
*
|
*
|
||||||
|
|
|
@ -98,6 +98,15 @@ public interface CommentService {
|
||||||
*/
|
*/
|
||||||
List<Comment> findCommentsByPostAndCommentStatus(Post post, Integer status);
|
List<Comment> findCommentsByPostAndCommentStatus(Post post, Integer status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据文章和评论状态(为不查询的)查询评论 不分页
|
||||||
|
*
|
||||||
|
* @param post post
|
||||||
|
* @param status status
|
||||||
|
* @return List
|
||||||
|
*/
|
||||||
|
List<Comment> findCommentsByPostAndCommentStatusNot(Post post, Integer status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询最新的前五条评论
|
* 查询最新的前五条评论
|
||||||
*
|
*
|
||||||
|
|
|
@ -151,6 +151,18 @@ public class CommentServiceImpl implements CommentService {
|
||||||
return commentRepository.findCommentsByPostAndCommentStatus(post, status);
|
return commentRepository.findCommentsByPostAndCommentStatus(post, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据文章和评论状态(为不查询的)查询评论 不分页
|
||||||
|
*
|
||||||
|
* @param post post
|
||||||
|
* @param status status
|
||||||
|
* @return List
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Comment> findCommentsByPostAndCommentStatusNot(Post post, Integer status) {
|
||||||
|
return commentRepository.findCommentsByPostAndCommentStatusNot(post, status);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询最新的前五条评论
|
* 查询最新的前五条评论
|
||||||
*
|
*
|
||||||
|
|
|
@ -2,14 +2,14 @@ package cc.ryanc.halo.web.controller.front;
|
||||||
|
|
||||||
import cc.ryanc.halo.model.domain.Comment;
|
import cc.ryanc.halo.model.domain.Comment;
|
||||||
import cc.ryanc.halo.model.domain.Post;
|
import cc.ryanc.halo.model.domain.Post;
|
||||||
import cc.ryanc.halo.model.enums.CommentStatus;
|
import cc.ryanc.halo.model.dto.HaloConst;
|
||||||
import cc.ryanc.halo.model.enums.PostStatus;
|
import cc.ryanc.halo.model.enums.*;
|
||||||
import cc.ryanc.halo.model.enums.PostType;
|
|
||||||
import cc.ryanc.halo.service.CommentService;
|
import cc.ryanc.halo.service.CommentService;
|
||||||
import cc.ryanc.halo.service.PostService;
|
import cc.ryanc.halo.service.PostService;
|
||||||
import cc.ryanc.halo.utils.CommentUtil;
|
import cc.ryanc.halo.utils.CommentUtil;
|
||||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
@ -118,7 +118,12 @@ public class FrontArchiveController extends BaseController {
|
||||||
if (null != afterPosts && afterPosts.size() > 0) {
|
if (null != afterPosts && afterPosts.size() > 0) {
|
||||||
model.addAttribute("afterPost", afterPosts.get(afterPosts.size() - 1));
|
model.addAttribute("afterPost", afterPosts.get(afterPosts.size() - 1));
|
||||||
}
|
}
|
||||||
List<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post, CommentStatus.PUBLISHED.getCode());
|
List<Comment> comments = null;
|
||||||
|
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.NEW_COMMENT_NEED_CHECK.getProp()), TrueFalse.TRUE.getDesc()) || HaloConst.OPTIONS.get(BlogProperties.NEW_COMMENT_NEED_CHECK.getProp()) == null) {
|
||||||
|
comments = commentService.findCommentsByPostAndCommentStatus(post, CommentStatus.PUBLISHED.getCode());
|
||||||
|
} else {
|
||||||
|
comments = commentService.findCommentsByPostAndCommentStatusNot(post, CommentStatus.RECYCLE.getCode());
|
||||||
|
}
|
||||||
model.addAttribute("post", post);
|
model.addAttribute("post", post);
|
||||||
model.addAttribute("comments", CommentUtil.getComments(comments));
|
model.addAttribute("comments", CommentUtil.getComments(comments));
|
||||||
model.addAttribute("commentsCount", comments.size());
|
model.addAttribute("commentsCount", comments.size());
|
||||||
|
|
|
@ -131,7 +131,11 @@ public class FrontCommentController {
|
||||||
} else {
|
} else {
|
||||||
new EmailToAdmin(comment, post).start();
|
new EmailToAdmin(comment, post).start();
|
||||||
}
|
}
|
||||||
|
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.NEW_COMMENT_NEED_CHECK.getProp()), TrueFalse.TRUE.getDesc()) || HaloConst.OPTIONS.get(BlogProperties.NEW_COMMENT_NEED_CHECK.getProp()) == null) {
|
||||||
return new JsonResult(ResultCode.SUCCESS.getCode(), "你的评论已经提交,待博主审核之后可显示。");
|
return new JsonResult(ResultCode.SUCCESS.getCode(), "你的评论已经提交,待博主审核之后可显示。");
|
||||||
|
} else {
|
||||||
|
return new JsonResult(ResultCode.SUCCESS.getCode(), "你的评论已经提交,刷新后即可显示。");
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return new JsonResult(ResultCode.FAIL.getCode(), "评论失败!");
|
return new JsonResult(ResultCode.FAIL.getCode(), "评论失败!");
|
||||||
}
|
}
|
||||||
|
@ -148,6 +152,7 @@ public class FrontCommentController {
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
this.post = post;
|
this.post = post;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.SMTP_EMAIL_ENABLE.getProp()), TrueFalse.TRUE.getDesc()) && StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.NEW_COMMENT_NOTICE.getProp()), TrueFalse.TRUE.getDesc())) {
|
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.SMTP_EMAIL_ENABLE.getProp()), TrueFalse.TRUE.getDesc()) && StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.NEW_COMMENT_NOTICE.getProp()), TrueFalse.TRUE.getDesc())) {
|
||||||
|
|
|
@ -3,13 +3,17 @@ package cc.ryanc.halo.web.controller.front;
|
||||||
import cc.ryanc.halo.model.domain.Comment;
|
import cc.ryanc.halo.model.domain.Comment;
|
||||||
import cc.ryanc.halo.model.domain.Gallery;
|
import cc.ryanc.halo.model.domain.Gallery;
|
||||||
import cc.ryanc.halo.model.domain.Post;
|
import cc.ryanc.halo.model.domain.Post;
|
||||||
|
import cc.ryanc.halo.model.dto.HaloConst;
|
||||||
|
import cc.ryanc.halo.model.enums.BlogProperties;
|
||||||
import cc.ryanc.halo.model.enums.CommentStatus;
|
import cc.ryanc.halo.model.enums.CommentStatus;
|
||||||
import cc.ryanc.halo.model.enums.PostType;
|
import cc.ryanc.halo.model.enums.PostType;
|
||||||
|
import cc.ryanc.halo.model.enums.TrueFalse;
|
||||||
import cc.ryanc.halo.service.CommentService;
|
import cc.ryanc.halo.service.CommentService;
|
||||||
import cc.ryanc.halo.service.GalleryService;
|
import cc.ryanc.halo.service.GalleryService;
|
||||||
import cc.ryanc.halo.service.PostService;
|
import cc.ryanc.halo.service.PostService;
|
||||||
import cc.ryanc.halo.utils.CommentUtil;
|
import cc.ryanc.halo.utils.CommentUtil;
|
||||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
|
@ -69,7 +73,12 @@ public class FrontPageController extends BaseController {
|
||||||
if (null == post) {
|
if (null == post) {
|
||||||
return this.renderNotFound();
|
return this.renderNotFound();
|
||||||
}
|
}
|
||||||
List<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post, CommentStatus.PUBLISHED.getCode());
|
List<Comment> comments = null;
|
||||||
|
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.NEW_COMMENT_NEED_CHECK.getProp()), TrueFalse.TRUE.getDesc()) || HaloConst.OPTIONS.get(BlogProperties.NEW_COMMENT_NEED_CHECK.getProp()) == null) {
|
||||||
|
comments = commentService.findCommentsByPostAndCommentStatus(post, CommentStatus.PUBLISHED.getCode());
|
||||||
|
} else {
|
||||||
|
comments = commentService.findCommentsByPostAndCommentStatusNot(post, CommentStatus.RECYCLE.getCode());
|
||||||
|
}
|
||||||
model.addAttribute("post", post);
|
model.addAttribute("post", post);
|
||||||
model.addAttribute("comments", CommentUtil.getComments(comments));
|
model.addAttribute("comments", CommentUtil.getComments(comments));
|
||||||
model.addAttribute("commentsCount", comments.size());
|
model.addAttribute("commentsCount", comments.size());
|
||||||
|
|
|
@ -232,6 +232,17 @@
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-lg-2 col-sm-4 control-label">评论审核后才显示:</label>
|
||||||
|
<div class="col-lg-4 col-sm-8">
|
||||||
|
<label class="radio-inline">
|
||||||
|
<input type="radio" name="new_comment_need_check" value="true" ${((options.new_comment_need_check?default("true"))=='true')?string('checked','')}> 开启
|
||||||
|
</label>
|
||||||
|
<label class="radio-inline">
|
||||||
|
<input type="radio" name="new_comment_need_check" value="false" ${((options.new_comment_need_check?if_exists)=='false')?string('checked','')}> 关闭
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-lg-2 col-sm-4 control-label">新评论通知:</label>
|
<label class="col-lg-2 col-sm-4 control-label">新评论通知:</label>
|
||||||
<div class="col-lg-4 col-sm-8">
|
<div class="col-lg-4 col-sm-8">
|
||||||
|
|
|
@ -388,6 +388,7 @@
|
||||||
$(".native-message").fadeOut(1000);
|
$(".native-message").fadeOut(1000);
|
||||||
$("#btn-push").removeAttr("disabled");
|
$("#btn-push").removeAttr("disabled");
|
||||||
$("#btn-push").html("提交");
|
$("#btn-push").html("提交");
|
||||||
|
window.location.reload();
|
||||||
},1500);
|
},1500);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue