refactor: optimize post update listener code (#1827)

pull/1832/head
guqing 2022-04-08 12:58:17 +08:00 committed by GitHub
parent e93092da24
commit 57965ed934
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -147,15 +147,16 @@ public class PostRefreshStatusListener {
} }
PostStatus status = post.getStatus(); PostStatus status = post.getStatus();
if (PostStatus.RECYCLE.equals(status)) {
return;
}
boolean isPrivate = postCategoryService.listByPostId(post.getId()) boolean isPrivate = postCategoryService.listByPostId(post.getId())
.stream() .stream()
.anyMatch(postCategory -> categoryService.isPrivate(postCategory.getCategoryId())); .anyMatch(postCategory -> categoryService.isPrivate(postCategory.getCategoryId()));
if (post.getStatus() != PostStatus.DRAFT) { if (post.getStatus() != PostStatus.DRAFT) {
if (StringUtils.isNotEmpty(post.getPassword())) { if (isPrivate || StringUtils.isNotEmpty(post.getPassword())) {
status = PostStatus.INTIMATE; status = PostStatus.INTIMATE;
} else if (isPrivate && !PostStatus.RECYCLE.equals(status)) { } else {
status = PostStatus.INTIMATE;
} else if (!PostStatus.RECYCLE.equals(status)) {
status = PostStatus.PUBLISHED; status = PostStatus.PUBLISHED;
} }
} else if (!isPrivate && StringUtils.isBlank(post.getPassword())) { } else if (!isPrivate && StringUtils.isBlank(post.getPassword())) {