Search in sources :

Example 1 with SheetComment

use of run.halo.app.model.entity.SheetComment in project halo by ruibaby.

the class CommentEventListener method handleCommentReplyEvent.

/**
 * Received a new reply comment event.
 *
 * @param replyEvent reply comment event.
 */
@Async
@EventListener
public void handleCommentReplyEvent(CommentReplyEvent replyEvent) {
    Boolean replyCommentNotice = optionService.getByPropertyOrDefault(CommentProperties.REPLY_NOTICE, Boolean.class, false);
    if (!replyCommentNotice) {
        // Skip mailing
        return;
    }
    String baseAuthorEmail = "";
    String blogTitle = optionService.getBlogTitle();
    Map<String, Object> data = new HashMap<>();
    StringBuilder subject = new StringBuilder();
    Boolean enabledAbsolutePath = optionService.isEnabledAbsolutePath();
    log.debug("replyEvent.getSource():" + replyEvent.getSource().toString());
    if (replyEvent.getSource() instanceof PostCommentService) {
        PostComment postComment = postCommentService.getById(replyEvent.getCommentId());
        PostComment baseComment = postCommentService.getById(postComment.getParentId());
        if (StringUtils.isEmpty(baseComment.getEmail()) && !ValidationUtils.isEmail(baseComment.getEmail())) {
            return;
        }
        if (!baseComment.getAllowNotification()) {
            return;
        }
        baseAuthorEmail = baseComment.getEmail();
        BasePostMinimalDTO post = postAssembler.convertToMinimal(postService.getById(postComment.getPostId()));
        data.put("pageFullPath", enabledAbsolutePath ? post.getFullPath() : optionService.getBlogBaseUrl() + post.getFullPath());
        data.put("pageTitle", post.getTitle());
        data.put("baseAuthor", baseComment.getAuthor());
        data.put("baseContent", baseComment.getContent());
        data.put("replyAuthor", postComment.getAuthor());
        data.put("replyContent", postComment.getContent());
        subject.append("您在【").append(blogTitle).append("】评论的文章《").append(post.getTitle()).append("》有了新的评论。");
    } else if (replyEvent.getSource() instanceof SheetCommentService) {
        SheetComment sheetComment = sheetCommentService.getById(replyEvent.getCommentId());
        SheetComment baseComment = sheetCommentService.getById(sheetComment.getParentId());
        if (StringUtils.isEmpty(baseComment.getEmail()) && !ValidationUtils.isEmail(baseComment.getEmail())) {
            return;
        }
        if (!baseComment.getAllowNotification()) {
            return;
        }
        baseAuthorEmail = baseComment.getEmail();
        BasePostMinimalDTO sheet = sheetAssembler.convertToMinimal(sheetService.getById(sheetComment.getPostId()));
        data.put("pageFullPath", enabledAbsolutePath ? sheet.getFullPath() : optionService.getBlogBaseUrl() + sheet.getFullPath());
        data.put("pageTitle", sheet.getTitle());
        data.put("baseAuthor", baseComment.getAuthor());
        data.put("baseContent", baseComment.getContent());
        data.put("replyAuthor", sheetComment.getAuthor());
        data.put("replyContent", sheetComment.getContent());
        subject.append("您在【").append(blogTitle).append("】评论的页面《").append(sheet.getTitle()).append("》有了新的评论。");
    } else if (replyEvent.getSource() instanceof JournalCommentService) {
        JournalComment journalComment = journalCommentService.getById(replyEvent.getCommentId());
        JournalComment baseComment = journalCommentService.getById(journalComment.getParentId());
        if (StringUtils.isEmpty(baseComment.getEmail()) && !ValidationUtils.isEmail(baseComment.getEmail())) {
            return;
        }
        if (!baseComment.getAllowNotification()) {
            return;
        }
        baseAuthorEmail = baseComment.getEmail();
        Journal journal = journalService.getById(journalComment.getPostId());
        StringBuilder url = new StringBuilder(optionService.getBlogBaseUrl()).append("/").append(optionService.getJournalsPrefix());
        data.put("pageFullPath", url);
        data.put("pageTitle", journal.getContent());
        data.put("baseAuthor", baseComment.getAuthor());
        data.put("baseContent", baseComment.getContent());
        data.put("replyAuthor", journalComment.getAuthor());
        data.put("replyContent", journalComment.getContent());
        subject.append("您在【").append(blogTitle).append("】评论的日志").append("有了新的评论。");
    }
    String template = "common/mail_template/mail_reply.ftl";
    if (themeService.templateExists("mail_template/mail_reply.ftl")) {
        template = themeService.renderWithSuffix("mail_template/mail_reply");
    }
    mailService.sendTemplateMail(baseAuthorEmail, subject.toString(), data, template);
}
Also used : SheetComment(run.halo.app.model.entity.SheetComment) PostCommentService(run.halo.app.service.PostCommentService) HashMap(java.util.HashMap) JournalComment(run.halo.app.model.entity.JournalComment) Journal(run.halo.app.model.entity.Journal) PostComment(run.halo.app.model.entity.PostComment) BasePostMinimalDTO(run.halo.app.model.dto.post.BasePostMinimalDTO) SheetCommentService(run.halo.app.service.SheetCommentService) JournalCommentService(run.halo.app.service.JournalCommentService) Async(org.springframework.scheduling.annotation.Async) EventListener(org.springframework.context.event.EventListener)

Example 2 with SheetComment

use of run.halo.app.model.entity.SheetComment in project halo by ruibaby.

the class BackupServiceImpl method importData.

@Override
public void importData(MultipartFile file) throws IOException {
    String jsonContent = FileUtils.readString(file.getInputStream());
    ObjectMapper mapper = JsonUtils.createDefaultJsonMapper();
    TypeReference<HashMap<String, Object>> typeRef = new TypeReference<>() {
    };
    HashMap<String, Object> data = mapper.readValue(jsonContent, typeRef);
    String version = (String) Objects.requireNonNullElse(data.get("version"), "");
    if (!VersionUtil.hasSameMajorAndMinorVersion(HaloConst.HALO_VERSION, version)) {
        throw new BadRequestException("导入数据的主次版本号与当前系统版本号不匹配,不支持导入!");
    }
    List<Attachment> attachments = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("attachments")), Attachment[].class));
    attachmentService.createInBatch(attachments);
    List<Category> categories = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("categories")), Category[].class));
    categoryService.createInBatch(categories);
    List<Tag> tags = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("tags")), Tag[].class));
    tagService.createInBatch(tags);
    List<CommentBlackList> commentBlackList = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("comment_black_list")), CommentBlackList[].class));
    commentBlackListService.createInBatch(commentBlackList);
    List<Journal> journals = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("journals")), Journal[].class));
    journalService.createInBatch(journals);
    List<JournalComment> journalComments = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("journal_comments")), JournalComment[].class));
    journalCommentService.createInBatch(journalComments);
    List<Link> links = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("links")), Link[].class));
    linkService.createInBatch(links);
    List<Log> logs = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("logs")), Log[].class));
    logService.createInBatch(logs);
    List<Menu> menus = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("menus")), Menu[].class));
    menuService.createInBatch(menus);
    List<Option> options = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("options")), Option[].class));
    optionService.createInBatch(options);
    eventPublisher.publishEvent(new OptionUpdatedEvent(this));
    List<Photo> photos = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("photos")), Photo[].class));
    photoService.createInBatch(photos);
    List<Post> posts = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("posts")), Post[].class));
    postService.createInBatch(posts);
    List<Content> contents = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("contents")), Content[].class));
    contentService.createInBatch(contents);
    List<ContentPatchLog> contentPatchLogs = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("content_patch_logs")), ContentPatchLog[].class));
    contentPatchLogService.createInBatch(contentPatchLogs);
    List<PostCategory> postCategories = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("post_categories")), PostCategory[].class));
    postCategoryService.createInBatch(postCategories);
    List<PostComment> postComments = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("post_comments")), PostComment[].class));
    postCommentService.createInBatch(postComments);
    List<PostMeta> postMetas = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("post_metas")), PostMeta[].class));
    postMetaService.createInBatch(postMetas);
    List<PostTag> postTags = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("post_tags")), PostTag[].class));
    postTagService.createInBatch(postTags);
    List<Sheet> sheets = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("sheets")), Sheet[].class));
    sheetService.createInBatch(sheets);
    List<SheetComment> sheetComments = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("sheet_comments")), SheetComment[].class));
    sheetCommentService.createInBatch(sheetComments);
    List<SheetMeta> sheetMetas = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("sheet_metas")), SheetMeta[].class));
    sheetMetaService.createInBatch(sheetMetas);
    List<ThemeSetting> themeSettings = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("theme_settings")), ThemeSetting[].class));
    themeSettingService.createInBatch(themeSettings);
    eventPublisher.publishEvent(new ThemeUpdatedEvent(this));
    List<User> users = Arrays.asList(mapper.readValue(mapper.writeValueAsString(data.get("user")), User[].class));
    if (users.size() > 0) {
        userService.create(users.get(0));
    }
}
Also used : SheetMeta(run.halo.app.model.entity.SheetMeta) HashMap(java.util.HashMap) JournalComment(run.halo.app.model.entity.JournalComment) Attachment(run.halo.app.model.entity.Attachment) Journal(run.halo.app.model.entity.Journal) Photo(run.halo.app.model.entity.Photo) ContentPatchLog(run.halo.app.model.entity.ContentPatchLog) PostComment(run.halo.app.model.entity.PostComment) PostMeta(run.halo.app.model.entity.PostMeta) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ContentPatchLog(run.halo.app.model.entity.ContentPatchLog) Log(run.halo.app.model.entity.Log) Content(run.halo.app.model.entity.Content) ThemeUpdatedEvent(run.halo.app.event.theme.ThemeUpdatedEvent) Option(run.halo.app.model.entity.Option) CommentBlackList(run.halo.app.model.entity.CommentBlackList) Link(run.halo.app.model.entity.Link) SheetComment(run.halo.app.model.entity.SheetComment) Category(run.halo.app.model.entity.Category) PostCategory(run.halo.app.model.entity.PostCategory) User(run.halo.app.model.entity.User) OptionUpdatedEvent(run.halo.app.event.options.OptionUpdatedEvent) PostCategory(run.halo.app.model.entity.PostCategory) ThemeSetting(run.halo.app.model.entity.ThemeSetting) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Menu(run.halo.app.model.entity.Menu) PostTag(run.halo.app.model.entity.PostTag) Post(run.halo.app.model.entity.Post) BadRequestException(run.halo.app.exception.BadRequestException) PostTag(run.halo.app.model.entity.PostTag) Tag(run.halo.app.model.entity.Tag) Sheet(run.halo.app.model.entity.Sheet)

Example 3 with SheetComment

use of run.halo.app.model.entity.SheetComment in project halo by ruibaby.

the class SheetServiceImpl method removeById.

@Override
public Sheet removeById(Integer id) {
    // Remove sheet metas
    List<SheetMeta> metas = sheetMetaService.removeByPostId(id);
    log.debug("Removed sheet metas: [{}]", metas);
    // Remove sheet comments
    List<SheetComment> sheetComments = sheetCommentService.removeByPostId(id);
    log.debug("Removed sheet comments: [{}]", sheetComments);
    // Remove sheet content
    Content sheetContent = sheetContentService.removeById(id);
    log.debug("Removed sheet content: [{}]", sheetContent);
    Sheet sheet = super.removeById(id);
    // Log it
    eventPublisher.publishEvent(new LogEvent(this, id.toString(), LogType.SHEET_DELETED, sheet.getTitle()));
    return sheet;
}
Also used : SheetComment(run.halo.app.model.entity.SheetComment) SheetMeta(run.halo.app.model.entity.SheetMeta) LogEvent(run.halo.app.event.logger.LogEvent) PatchedContent(run.halo.app.model.entity.Content.PatchedContent) Content(run.halo.app.model.entity.Content) Sheet(run.halo.app.model.entity.Sheet)

Example 4 with SheetComment

use of run.halo.app.model.entity.SheetComment in project halo by ruibaby.

the class SheetCommentController method updateBy.

@PutMapping("{commentId:\\d+}")
@ApiOperation("Updates a sheet comment")
public BaseCommentDTO updateBy(@Valid @RequestBody SheetCommentParam commentParam, @PathVariable("commentId") Long commentId) {
    SheetComment commentToUpdate = sheetCommentService.getById(commentId);
    commentParam.update(commentToUpdate);
    return sheetCommentService.convertTo(sheetCommentService.update(commentToUpdate));
}
Also used : SheetComment(run.halo.app.model.entity.SheetComment) PutMapping(org.springframework.web.bind.annotation.PutMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with SheetComment

use of run.halo.app.model.entity.SheetComment in project halo-plugin-experimental by guqing.

the class CommentEventListener method handleCommentReplyEvent.

/**
 * Received a new reply comment event.
 *
 * @param replyEvent reply comment event.
 */
@Async
@EventListener
public void handleCommentReplyEvent(CommentReplyEvent replyEvent) {
    Boolean replyCommentNotice = optionService.getByPropertyOrDefault(CommentProperties.REPLY_NOTICE, Boolean.class, false);
    if (!replyCommentNotice) {
        // Skip mailing
        return;
    }
    String baseAuthorEmail = "";
    String blogTitle = optionService.getBlogTitle();
    Map<String, Object> data = new HashMap<>();
    StringBuilder subject = new StringBuilder();
    Boolean enabledAbsolutePath = optionService.isEnabledAbsolutePath();
    log.debug("replyEvent.getSource():" + replyEvent.getSource().toString());
    if (replyEvent.getSource() instanceof PostCommentService) {
        PostComment postComment = postCommentService.getById(replyEvent.getCommentId());
        PostComment baseComment = postCommentService.getById(postComment.getParentId());
        if (StringUtils.isEmpty(baseComment.getEmail()) && !ValidationUtils.isEmail(baseComment.getEmail())) {
            return;
        }
        if (!baseComment.getAllowNotification()) {
            return;
        }
        baseAuthorEmail = baseComment.getEmail();
        BasePostMinimalDTO post = postService.convertToMinimal(postService.getById(postComment.getPostId()));
        data.put("pageFullPath", enabledAbsolutePath ? post.getFullPath() : optionService.getBlogBaseUrl() + post.getFullPath());
        data.put("pageTitle", post.getTitle());
        data.put("baseAuthor", baseComment.getAuthor());
        data.put("baseContent", baseComment.getContent());
        data.put("replyAuthor", postComment.getAuthor());
        data.put("replyContent", postComment.getContent());
        subject.append("您在【").append(blogTitle).append("】评论的文章《").append(post.getTitle()).append("》有了新的评论。");
    } else if (replyEvent.getSource() instanceof SheetCommentService) {
        SheetComment sheetComment = sheetCommentService.getById(replyEvent.getCommentId());
        SheetComment baseComment = sheetCommentService.getById(sheetComment.getParentId());
        if (StringUtils.isEmpty(baseComment.getEmail()) && !ValidationUtils.isEmail(baseComment.getEmail())) {
            return;
        }
        if (!baseComment.getAllowNotification()) {
            return;
        }
        baseAuthorEmail = baseComment.getEmail();
        BasePostMinimalDTO sheet = sheetService.convertToMinimal(sheetService.getById(sheetComment.getPostId()));
        data.put("pageFullPath", enabledAbsolutePath ? sheet.getFullPath() : optionService.getBlogBaseUrl() + sheet.getFullPath());
        data.put("pageTitle", sheet.getTitle());
        data.put("baseAuthor", baseComment.getAuthor());
        data.put("baseContent", baseComment.getContent());
        data.put("replyAuthor", sheetComment.getAuthor());
        data.put("replyContent", sheetComment.getContent());
        subject.append("您在【").append(blogTitle).append("】评论的页面《").append(sheet.getTitle()).append("》有了新的评论。");
    } else if (replyEvent.getSource() instanceof JournalCommentService) {
        JournalComment journalComment = journalCommentService.getById(replyEvent.getCommentId());
        JournalComment baseComment = journalCommentService.getById(journalComment.getParentId());
        if (StringUtils.isEmpty(baseComment.getEmail()) && !ValidationUtils.isEmail(baseComment.getEmail())) {
            return;
        }
        if (!baseComment.getAllowNotification()) {
            return;
        }
        baseAuthorEmail = baseComment.getEmail();
        Journal journal = journalService.getById(journalComment.getPostId());
        StringBuilder url = new StringBuilder(optionService.getBlogBaseUrl()).append("/").append(optionService.getJournalsPrefix());
        data.put("pageFullPath", url);
        data.put("pageTitle", journal.getContent());
        data.put("baseAuthor", baseComment.getAuthor());
        data.put("baseContent", baseComment.getContent());
        data.put("replyAuthor", journalComment.getAuthor());
        data.put("replyContent", journalComment.getContent());
        subject.append("您在【").append(blogTitle).append("】评论的日志").append("有了新的评论。");
    }
    String template = "common/mail_template/mail_reply.ftl";
    if (themeService.templateExists("mail_template/mail_reply.ftl")) {
        template = themeService.renderWithSuffix("mail_template/mail_reply");
    }
    mailService.sendTemplateMail(baseAuthorEmail, subject.toString(), data, template);
}
Also used : SheetComment(run.halo.app.model.entity.SheetComment) PostCommentService(run.halo.app.service.PostCommentService) HashMap(java.util.HashMap) JournalComment(run.halo.app.model.entity.JournalComment) Journal(run.halo.app.model.entity.Journal) PostComment(run.halo.app.model.entity.PostComment) BasePostMinimalDTO(run.halo.app.model.dto.post.BasePostMinimalDTO) SheetCommentService(run.halo.app.service.SheetCommentService) JournalCommentService(run.halo.app.service.JournalCommentService) Async(org.springframework.scheduling.annotation.Async) EventListener(org.springframework.context.event.EventListener)

Aggregations

SheetComment (run.halo.app.model.entity.SheetComment)15 HashMap (java.util.HashMap)9 Journal (run.halo.app.model.entity.Journal)9 JournalComment (run.halo.app.model.entity.JournalComment)9 PostComment (run.halo.app.model.entity.PostComment)9 EventListener (org.springframework.context.event.EventListener)6 Async (org.springframework.scheduling.annotation.Async)6 BasePostMinimalDTO (run.halo.app.model.dto.post.BasePostMinimalDTO)6 Sheet (run.halo.app.model.entity.Sheet)6 SheetMeta (run.halo.app.model.entity.SheetMeta)6 User (run.halo.app.model.entity.User)6 JournalCommentService (run.halo.app.service.JournalCommentService)6 PostCommentService (run.halo.app.service.PostCommentService)6 SheetCommentService (run.halo.app.service.SheetCommentService)6 Content (run.halo.app.model.entity.Content)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ApiOperation (io.swagger.annotations.ApiOperation)3 PutMapping (org.springframework.web.bind.annotation.PutMapping)3 LogEvent (run.halo.app.event.logger.LogEvent)3