mirror of https://github.com/halo-dev/halo
Complate CommentEventListener.
parent
147b8ce225
commit
0a3717e394
|
@ -6,10 +6,7 @@ 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.PostComment;
|
||||
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.entity.*;
|
||||
import run.halo.app.model.properties.CommentProperties;
|
||||
import run.halo.app.service.*;
|
||||
|
||||
|
@ -32,19 +29,27 @@ public class CommentEventListener {
|
|||
|
||||
private final PostCommentService postCommentService;
|
||||
|
||||
private final SheetCommentService sheetCommentService;
|
||||
|
||||
private final JournalCommentService journalCommentService;
|
||||
|
||||
private final PostService postService;
|
||||
|
||||
private final SheetService sheetService;
|
||||
|
||||
private final JournalService journalService;
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
public CommentEventListener(MailService mailService,
|
||||
OptionService optionService,
|
||||
PostCommentService postCommentService,
|
||||
PostService postService,
|
||||
UserService userService) {
|
||||
public CommentEventListener(MailService mailService, OptionService optionService, PostCommentService postCommentService, SheetCommentService sheetCommentService, JournalCommentService journalCommentService, PostService postService, SheetService sheetService, JournalService journalService, UserService userService) {
|
||||
this.mailService = mailService;
|
||||
this.optionService = optionService;
|
||||
this.postCommentService = postCommentService;
|
||||
this.sheetCommentService = sheetCommentService;
|
||||
this.journalCommentService = journalCommentService;
|
||||
this.postService = postService;
|
||||
this.sheetService = sheetService;
|
||||
this.journalService = journalService;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
|
@ -60,37 +65,54 @@ public class CommentEventListener {
|
|||
|
||||
User user = userService.getCurrentUser().orElseThrow(() -> new ServiceException("Can not find blog owner"));
|
||||
|
||||
// Get postComment id
|
||||
PostComment postComment = postCommentService.getById(newEvent.getCommentId());
|
||||
|
||||
Post post = postService.getById(postComment.getPostId());
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
|
||||
StrBuilder url = new StrBuilder(optionService.getByPropertyOfNullable(BlogProperties.BLOG_URL).toString())
|
||||
.append("/archives/")
|
||||
.append(post.getUrl());
|
||||
data.put("url", url.toString());
|
||||
data.put("page", post.getTitle());
|
||||
data.put("author", postComment.getAuthor());
|
||||
data.put("content", postComment.getContent());
|
||||
if (this instanceof PostService) {
|
||||
// Get postComment id
|
||||
PostComment postComment = postCommentService.getById(newEvent.getCommentId());
|
||||
|
||||
Post post = postService.getById(postComment.getPostId());
|
||||
|
||||
StrBuilder url = new StrBuilder(optionService.getBlogBaseUrl())
|
||||
.append("/archives/")
|
||||
.append(post.getUrl());
|
||||
data.put("url", url.toString());
|
||||
data.put("page", post.getTitle());
|
||||
data.put("author", postComment.getAuthor());
|
||||
data.put("content", postComment.getContent());
|
||||
} else if (this instanceof SheetService) {
|
||||
SheetComment sheetComment = sheetCommentService.getById(newEvent.getCommentId());
|
||||
|
||||
Sheet sheet = sheetService.getById(sheetComment.getPostId());
|
||||
|
||||
StrBuilder url = new StrBuilder(optionService.getBlogBaseUrl())
|
||||
.append("/s/")
|
||||
.append(sheet.getUrl());
|
||||
data.put("url", url.toString());
|
||||
data.put("page", sheet.getTitle());
|
||||
data.put("author", sheetComment.getAuthor());
|
||||
data.put("content", sheetComment.getContent());
|
||||
} else if (this instanceof JournalService) {
|
||||
JournalComment journalComment = journalCommentService.getById(newEvent.getCommentId());
|
||||
|
||||
Journal journal = journalService.getById(journalComment.getPostId());
|
||||
|
||||
StrBuilder url = new StrBuilder(optionService.getBlogBaseUrl())
|
||||
.append("/journals");
|
||||
data.put("url", url.toString());
|
||||
data.put("page", journal.getCreateTime());
|
||||
data.put("author", journalComment.getAuthor());
|
||||
data.put("content", journalComment.getContent());
|
||||
}
|
||||
|
||||
mailService.sendTemplateMail(user.getEmail(), "您的博客有新的评论", data, "common/mail_template/mail_notice.ftl");
|
||||
}
|
||||
|
||||
@Async
|
||||
@EventListener
|
||||
public void handleCommentPassEvent(CommentPassEvent passEvent) {
|
||||
Boolean passCommentNotice = optionService.getByPropertyOrDefault(CommentProperties.PASS_NOTICE, Boolean.class, false);
|
||||
|
||||
if (!passCommentNotice) {
|
||||
// Skip mailing
|
||||
return;
|
||||
}
|
||||
|
||||
// Get postComment id
|
||||
PostComment postComment = postCommentService.getById(passEvent.getCommentId());
|
||||
|
||||
// TODO Complete mail sending
|
||||
}
|
||||
|
||||
@Async
|
||||
|
@ -103,10 +125,65 @@ public class CommentEventListener {
|
|||
return;
|
||||
}
|
||||
|
||||
// Get postComment id
|
||||
PostComment postComment = postCommentService.getById(replyEvent.getCommentId());
|
||||
User user = userService.getCurrentUser().orElseThrow(() -> new ServiceException("Can not find blog owner"));
|
||||
|
||||
// TODO Complete mail sending
|
||||
String blogTitle = optionService.getBlogTitle();
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
|
||||
if (this instanceof PostService) {
|
||||
|
||||
PostComment postComment = postCommentService.getById(replyEvent.getCommentId());
|
||||
|
||||
PostComment baseComment = postCommentService.getById(postComment.getParentId());
|
||||
|
||||
Post post = postService.getById(postComment.getPostId());
|
||||
|
||||
StrBuilder url = new StrBuilder(optionService.getBlogBaseUrl())
|
||||
.append("/archives/")
|
||||
.append(post.getUrl());
|
||||
|
||||
data.put("url", url);
|
||||
data.put("page", post.getTitle());
|
||||
data.put("baseAuthor", baseComment.getAuthor());
|
||||
data.put("baseContent", baseComment.getContent());
|
||||
data.put("replyAuthor", postComment.getAuthor());
|
||||
data.put("replyContent", postComment.getContent());
|
||||
} else if (this instanceof SheetService) {
|
||||
|
||||
SheetComment sheetComment = sheetCommentService.getById(replyEvent.getCommentId());
|
||||
|
||||
SheetComment baseComment = sheetCommentService.getById(sheetComment.getParentId());
|
||||
|
||||
Sheet sheet = sheetService.getById(sheetComment.getPostId());
|
||||
|
||||
StrBuilder url = new StrBuilder(optionService.getBlogBaseUrl())
|
||||
.append("/s/")
|
||||
.append(sheet.getUrl());
|
||||
|
||||
data.put("url", url);
|
||||
data.put("page", sheet.getTitle());
|
||||
data.put("baseAuthor", baseComment.getAuthor());
|
||||
data.put("baseContent", baseComment.getContent());
|
||||
data.put("replyAuthor", sheetComment.getAuthor());
|
||||
data.put("replyContent", sheetComment.getContent());
|
||||
} else if (this instanceof JournalService) {
|
||||
JournalComment journalComment = journalCommentService.getById(replyEvent.getCommentId());
|
||||
|
||||
JournalComment baseComment = journalCommentService.getById(journalComment.getParentId());
|
||||
|
||||
Journal journal = journalService.getById(journalComment.getPostId());
|
||||
|
||||
StrBuilder url = new StrBuilder(optionService.getBlogBaseUrl())
|
||||
.append("/journals");
|
||||
data.put("url", url);
|
||||
data.put("page", journal.getContent());
|
||||
data.put("baseAuthor", baseComment.getAuthor());
|
||||
data.put("baseContent", baseComment.getContent());
|
||||
data.put("replyAuthor", journalComment.getAuthor());
|
||||
data.put("replyContent", journalComment.getContent());
|
||||
}
|
||||
|
||||
mailService.sendTemplateMail(user.getEmail(), "您在【" + blogTitle + "】的评论有新回复", data, "common/mail_template/mail_reply.ftl");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ public class PostParam implements InputConverter<Post> {
|
|||
@NotBlank(message = "Original content must not be blank")
|
||||
private String originalContent;
|
||||
|
||||
private String summary;
|
||||
|
||||
@Size(max = 255, message = "Length of thumbnail must not be more than {max}")
|
||||
private String thumbnail;
|
||||
|
||||
|
|
|
@ -288,6 +288,13 @@ public interface OptionService extends CrudService<Option, Integer> {
|
|||
@NonNull
|
||||
String getBlogBaseUrl();
|
||||
|
||||
/**
|
||||
* Gets blog title.
|
||||
* @return blog title.
|
||||
*/
|
||||
@NonNull
|
||||
String getBlogTitle();
|
||||
|
||||
/**
|
||||
* Gets blog birthday.
|
||||
*
|
||||
|
|
|
@ -379,6 +379,11 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
|||
return blogUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBlogTitle() {
|
||||
return getByProperty(BlogProperties.BLOG_TITLE).orElse("").toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBirthday() {
|
||||
return getByProperty(PrimaryProperties.BIRTHDAY, Long.class).orElseGet(() -> {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">有访客在《${page!}》留言:</p>
|
||||
<br />
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;padding:10px 20px;background:#f8f8f8;margin:0">
|
||||
${content!}:${commentContent!}
|
||||
${author!}:${content!}
|
||||
</p>
|
||||
<br />
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">你可以点击<a href="${url!}">查看完整内容</a></p>
|
||||
|
|
|
@ -2,28 +2,28 @@
|
|||
<div class="emailcontent" style="width:100%;max-width:720px;text-align: left;margin: 0 auto;padding-top: 20px;padding-bottom: 80px">
|
||||
<div class="emailtitle" style="border-radius: 5px;border:1px solid #eee;overflow: hidden;">
|
||||
<h1 style="color:#fff;background: #3798e8;line-height:70px;font-size:24px;font-weight:normal;padding-left:40px;margin:0">
|
||||
您在${blogTitle}上的留言有回复啦!
|
||||
您在 ${options.blog_title!} 上的留言有回复啦!
|
||||
</h1>
|
||||
<div class="emailtext" style="background:#fff;padding:20px 32px 40px;">
|
||||
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">${commentAuthor}, 您好!</p>
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">您在《${pageName}》的留言:
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">${baseAuthor}, 您好!</p>
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">您在《${page}》的留言:
|
||||
<br />
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;padding:10px 20px;background:#f8f8f8;margin:0px">${commentContent}</p>
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;padding:10px 20px;background:#f8f8f8;margin:0">${baseContent}</p>
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">${replyAuthor} 给你的回复:
|
||||
<br />
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;padding:10px 20px;background:#f8f8f8;margin:0px">${replyContent}</p>
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;padding:10px 20px;background:#f8f8f8;margin:0">${replyContent}</p>
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">你可以点击
|
||||
<a href="${pageUrl}">查看完整内容</a>
|
||||
<a href="${url}">查看完整内容</a>
|
||||
</p>
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">欢迎再度光临
|
||||
<a href="${blogUrl}">${blogTitle}</a>
|
||||
<a href="${options.blog_url!}">${options.blog_title!}</a>
|
||||
</p>
|
||||
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">(此邮件由系统自动发出, 请勿回复。)</p>
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">(此邮件由系统自动发出, 请勿回复。如有打扰,请见谅。)</p>
|
||||
</div>
|
||||
<p style="color: #6e6e6e;font-size:13px;line-height:24px;text-align:right;padding:0 32px">邮件发自:
|
||||
<a href="${blogUrl}" style="color:#51a0e3;text-decoration:none">${blogTitle}</a>
|
||||
<a href="${options.blog_url!}" style="color:#51a0e3;text-decoration:none">${options.blog_title!}</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue