Skip to content

Commit

Permalink
refactor: reply creation time
Browse files Browse the repository at this point in the history
  • Loading branch information
guqing committed Mar 13, 2024
1 parent 0f76008 commit 3aa90a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
@@ -1,5 +1,6 @@
package run.halo.app.core.extension.reconciler;

import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
import static run.halo.app.extension.ExtensionUtil.addFinalizers;

import java.util.Set;
Expand Down Expand Up @@ -45,6 +46,15 @@ public Result reconcile(Request request) {
eventPublisher.publishEvent(new ReplyCreatedEvent(this, reply));
}

if (reply.getSpec().getCreationTime() == null) {
reply.getSpec().setCreationTime(
defaultIfNull(reply.getSpec().getApprovedTime(),
reply.getMetadata().getCreationTimestamp()
)
);
}
client.update(reply);

replyNotificationSubscriptionHelper.subscribeNewReplyReasonForReply(reply);

eventPublisher.publishEvent(new ReplyChangedEvent(this, reply));
Expand Down
Expand Up @@ -223,7 +223,8 @@ public void onApplicationEvent(@NonNull ApplicationContextInitializedEvent event
indexSpecs.add(new IndexSpec()
.setName("spec.creationTime")
.setIndexFunc(simpleAttribute(Comment.class,
comment -> comment.getSpec().getCreationTime().toString())
comment -> defaultIfNull(comment.getSpec().getCreationTime(),
comment.getMetadata().getCreationTimestamp()).toString())
));
indexSpecs.add(new IndexSpec()
.setName("spec.approved")
Expand Down Expand Up @@ -286,7 +287,8 @@ public void onApplicationEvent(@NonNull ApplicationContextInitializedEvent event
indexSpecs.add(new IndexSpec()
.setName("spec.creationTime")
.setIndexFunc(simpleAttribute(Reply.class,
reply -> reply.getSpec().getCreationTime().toString())
reply -> defaultIfNull(reply.getSpec().getCreationTime(),
reply.getMetadata().getCreationTimestamp()).toString())
));
indexSpecs.add(new IndexSpec()
.setName("spec.commentName")
Expand Down

0 comments on commit 3aa90a6

Please sign in to comment.