From 7682318ae6a94d5f132c7742f597c5938d1e4678 Mon Sep 17 00:00:00 2001 From: guqing <38999863+guqing@users.noreply.github.com> Date: Fri, 26 Aug 2022 15:38:11 +0800 Subject: [PATCH] feat: update post in progress status when post changed (#2350) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind improvement /area core /milestone 2.0 #### What this PR does / why we need it: 文章更新时 reconcile 文章内容是否有草稿正在编辑,有则更新status.inProgress=true否则为false #### Which issue(s) this PR fixes: a part of #2322 #### Special notes for your reviewer: /cc @halo-dev/sig-halo #### Does this PR introduce a user-facing change? ```release-note None ``` --- .../core/extension/reconciler/PostReconciler.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/run/halo/app/core/extension/reconciler/PostReconciler.java b/src/main/java/run/halo/app/core/extension/reconciler/PostReconciler.java index c312cd05c..b0c167fa4 100644 --- a/src/main/java/run/halo/app/core/extension/reconciler/PostReconciler.java +++ b/src/main/java/run/halo/app/core/extension/reconciler/PostReconciler.java @@ -88,6 +88,7 @@ public class PostReconciler implements Reconciler { } // handle contributors + String headSnapshot = post.getSpec().getHeadSnapshot(); contentService.listSnapshots(Snapshot.SubjectRef.of(Post.KIND, name)) .collectList() .subscribe(snapshots -> { @@ -102,6 +103,14 @@ public class PostReconciler implements Reconciler { .sorted() .toList(); status.setContributors(contributors); + + // update in progress status + snapshots.stream() + .filter(snapshot -> snapshot.getMetadata().getName().equals(headSnapshot)) + .findAny() + .ifPresent(snapshot -> { + status.setInProgress(!isPublished(snapshot)); + }); }); // handle cancel publish,has released version and published is false and not handled @@ -149,4 +158,8 @@ public class PostReconciler implements Reconciler { // TODO The default capture 150 words as excerpt return StringUtils.substring(text, 0, 150); } + + private boolean isPublished(Snapshot snapshot) { + return snapshot.getSpec().getPublishTime() != null; + } }