diff --git a/.editorconfig b/.editorconfig index 3f5767e239..d21cc9b75e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,7 +9,7 @@ tab_width = 4 ij_continuation_indent_size = 8 ij_formatter_off_tag = @formatter:off ij_formatter_on_tag = @formatter:on -ij_formatter_tags_enabled = false +ij_formatter_tags_enabled = true ij_smart_tabs = false ij_wrap_on_typing = false diff --git a/api/src/main/java/run/halo/app/core/extension/content/Comment.java b/api/src/main/java/run/halo/app/core/extension/content/Comment.java index 068ca55fa8..5684826c73 100644 --- a/api/src/main/java/run/halo/app/core/extension/content/Comment.java +++ b/api/src/main/java/run/halo/app/core/extension/content/Comment.java @@ -45,6 +45,7 @@ public CommentStatus getStatusOrDefault() { } @Data + @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true) public static class CommentSpec extends BaseCommentSpec { diff --git a/application/src/main/java/run/halo/app/theme/finders/CommentFinder.java b/application/src/main/java/run/halo/app/theme/finders/CommentFinder.java index 2a14fe6fe3..a8cb0a2107 100644 --- a/application/src/main/java/run/halo/app/theme/finders/CommentFinder.java +++ b/application/src/main/java/run/halo/app/theme/finders/CommentFinder.java @@ -18,7 +18,7 @@ public interface CommentFinder { Mono getByName(String name); - Mono> list(Ref ref, @Nullable Integer page, + Mono> list(@Nullable Ref ref, @Nullable Integer page, @Nullable Integer size); Mono> listReply(String commentName, @Nullable Integer page, diff --git a/application/src/main/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceImpl.java b/application/src/main/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceImpl.java index 634c5dcd57..21c56609a2 100644 --- a/application/src/main/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceImpl.java +++ b/application/src/main/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceImpl.java @@ -11,6 +11,7 @@ import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.lang.Nullable; import org.springframework.security.core.context.ReactiveSecurityContextHolder; import org.springframework.security.core.context.SecurityContext; import org.springframework.stereotype.Component; @@ -44,6 +45,7 @@ @Component @RequiredArgsConstructor public class CommentPublicQueryServiceImpl implements CommentPublicQueryService { + private static final int DEFAULT_SIZE = 10; private final ReactiveExtensionClient client; private final UserService userService; @@ -117,7 +119,7 @@ Mono toCommentVo(Comment comment) { .doOnNext(commentVo::setOwner) .thenReturn(commentVo) ) - .flatMap(commentVo -> filterCommentSensitiveData(commentVo)); + .flatMap(this::filterCommentSensitiveData); } private Mono filterCommentSensitiveData(CommentVo commentVo) { @@ -138,8 +140,9 @@ private Mono filterCommentSensitiveData(CommentVo commentVo return Mono.just(commentVo); } - private Mono - populateStats(Class clazz, T vo) { + // @formatter:off + private + Mono populateStats(Class clazz, T vo) { return counterService.getByName(MeterUtils.nameOf(clazz, vo.getMetadata() .getName())) .map(counter -> CommentStatsVo.builder() @@ -148,6 +151,7 @@ private Mono filterCommentSensitiveData(CommentVo commentVo ) .defaultIfEmpty(CommentStatsVo.empty()); } + // @formatter:on Mono toReplyVo(Reply reply) { return Mono.just(ReplyVo.from(reply)) @@ -158,7 +162,7 @@ Mono toReplyVo(Reply reply) { .doOnNext(replyVo::setOwner) .thenReturn(replyVo) ) - .flatMap(replyVo -> filterReplySensitiveData(replyVo)); + .flatMap(this::filterReplySensitiveData); } private Mono filterReplySensitiveData(ReplyVo replyVo) { @@ -187,11 +191,13 @@ private Mono getOwnerInfo(Comment.CommentOwner owner) { .map(OwnerInfo::from); } - private Mono> fixedCommentPredicate(Ref ref) { - Assert.notNull(ref, "Comment subject reference must not be null"); - // Ref must be equal to the comment subject - Predicate refPredicate = comment -> comment.getSpec().getSubjectRef().equals(ref) - && comment.getMetadata().getDeletionTimestamp() == null; + private Mono> fixedCommentPredicate(@Nullable Ref ref) { + Predicate basePredicate = + comment -> comment.getMetadata().getDeletionTimestamp() == null; + if (ref != null) { + basePredicate = basePredicate + .and(comment -> comment.getSpec().getSubjectRef().equals(ref)); + } // is approved and not hidden Predicate approvedPredicate = @@ -206,7 +212,7 @@ private Mono> fixedCommentPredicate(Ref ref) { return approvedPredicate.or(isOwner); }) .defaultIfEmpty(approvedPredicate) - .map(refPredicate::and); + .map(basePredicate::and); } private Mono> fixedReplyPredicate(String commentName) { @@ -277,6 +283,6 @@ int pageNullSafe(Integer page) { } int sizeNullSafe(Integer size) { - return ObjectUtils.defaultIfNull(size, 10); + return ObjectUtils.defaultIfNull(size, DEFAULT_SIZE); } } diff --git a/application/src/main/java/run/halo/app/theme/finders/vo/CommentVo.java b/application/src/main/java/run/halo/app/theme/finders/vo/CommentVo.java index 1f25159557..a6725b3c07 100644 --- a/application/src/main/java/run/halo/app/theme/finders/vo/CommentVo.java +++ b/application/src/main/java/run/halo/app/theme/finders/vo/CommentVo.java @@ -1,5 +1,7 @@ package run.halo.app.theme.finders.vo; +import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; + import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; import lombok.Data; @@ -19,18 +21,18 @@ @EqualsAndHashCode public class CommentVo implements ExtensionVoOperator { - @Schema(required = true) + @Schema(requiredMode = REQUIRED) private MetadataOperator metadata; - @Schema(required = true) + @Schema(requiredMode = REQUIRED) private Comment.CommentSpec spec; private Comment.CommentStatus status; - @Schema(required = true) + @Schema(requiredMode = REQUIRED) private OwnerInfo owner; - @Schema(required = true) + @Schema(requiredMode = REQUIRED) private CommentStatsVo stats; /**