diff --git a/src/main/java/run/halo/app/event/comment/CommentEventListener.java b/src/main/java/run/halo/app/event/comment/CommentEventListener.java index 7e22287f7..e02ad533f 100644 --- a/src/main/java/run/halo/app/event/comment/CommentEventListener.java +++ b/src/main/java/run/halo/app/event/comment/CommentEventListener.java @@ -1,14 +1,21 @@ package run.halo.app.event.comment; +import cn.hutool.core.text.StrBuilder; import lombok.extern.slf4j.Slf4j; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; +import run.halo.app.exception.ServiceException; import run.halo.app.model.entity.Comment; +import run.halo.app.model.entity.Post; +import run.halo.app.model.entity.User; +import run.halo.app.model.properties.BlogProperties; import run.halo.app.model.properties.CommentProperties; -import run.halo.app.service.CommentService; -import run.halo.app.service.MailService; -import run.halo.app.service.OptionService; +import run.halo.app.service.*; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; /** * Comment event listener. @@ -26,12 +33,20 @@ public class CommentEventListener { private final CommentService commentService; + private final PostService postService; + + private final UserService userService; + public CommentEventListener(MailService mailService, OptionService optionService, - CommentService commentService) { + CommentService commentService, + PostService postService, + UserService userService) { this.mailService = mailService; this.optionService = optionService; this.commentService = commentService; + this.postService = postService; + this.userService = userService; } @Async @@ -44,10 +59,23 @@ public class CommentEventListener { return; } + User user = userService.getCurrentUser().orElseThrow(() -> new ServiceException("Can not find blog owner")); + // Get comment id Comment comment = commentService.getById(newEvent.getCommentId()); - // TODO Complete mail sending + Post post = postService.getById(comment.getPostId()); + + Map data = new HashMap<>(); + + StrBuilder url = new StrBuilder(optionService.getByPropertyOfNullable(BlogProperties.BLOG_URL)) + .append("/archives/") + .append(post.getUrl()); + data.put("url", url.toString()); + data.put("page", post.getTitle()); + data.put("author", comment.getAuthor()); + data.put("content",comment.getContent()); + mailService.sendTemplateMail(user.getEmail(), "您的博客有新的评论", data, "common/mail_template/mail_notice.ftl"); } @Async diff --git a/src/main/java/run/halo/app/web/controller/admin/MainController.java b/src/main/java/run/halo/app/web/controller/admin/MainController.java new file mode 100644 index 000000000..feef21547 --- /dev/null +++ b/src/main/java/run/halo/app/web/controller/admin/MainController.java @@ -0,0 +1,20 @@ +package run.halo.app.web.controller.admin; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +/** + * Admin page. + * + * @author : RYAN0UP + * @date : 2019-04-23 + */ +@Controller +public class MainController { + + + @GetMapping("/admin") + public String admin() { + return "redirect:/admin/index.html"; + } +} diff --git a/src/main/java/run/halo/app/web/controller/content/ContentArchiveController.java b/src/main/java/run/halo/app/web/controller/content/ContentArchiveController.java index 501bd18ff..6029a2146 100644 --- a/src/main/java/run/halo/app/web/controller/content/ContentArchiveController.java +++ b/src/main/java/run/halo/app/web/controller/content/ContentArchiveController.java @@ -33,7 +33,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC; */ @Slf4j @Controller -@RequestMapping(value = "archives") +@RequestMapping(value = "/archives") public class ContentArchiveController { private final PostService postService; diff --git a/src/main/java/run/halo/app/web/controller/content/ContentIndexController.java b/src/main/java/run/halo/app/web/controller/content/ContentIndexController.java index ed4ec203d..3c91545a0 100644 --- a/src/main/java/run/halo/app/web/controller/content/ContentIndexController.java +++ b/src/main/java/run/halo/app/web/controller/content/ContentIndexController.java @@ -83,9 +83,4 @@ public class ContentIndexController { model.addAttribute("rainbow", rainbow); return themeService.render("index"); } - - @GetMapping("/admin") - public String admin() { - return "redirect:/admin/index.html"; - } } diff --git a/src/main/resources/templates/common/mail_template/mail_admin.ftl b/src/main/resources/templates/common/mail_template/mail_notice.ftl similarity index 77% rename from src/main/resources/templates/common/mail_template/mail_admin.ftl rename to src/main/resources/templates/common/mail_template/mail_notice.ftl index 145f9b5c5..cc7c9a32d 100644 --- a/src/main/resources/templates/common/mail_template/mail_admin.ftl +++ b/src/main/resources/templates/common/mail_template/mail_notice.ftl @@ -5,14 +5,14 @@ 您的博客有新的评论!
-

${author}, 您好!

-

有访客在《${pageName}》留言:

+

${user.nickName!}, 您好!

+

有访客在《${page!}》留言:


-

- ${visitor}:${commentContent} +

+ ${content!}:${commentContent!}


-

你可以点击查看完整内容

+

你可以点击查看完整内容