diff --git a/api/src/main/java/run/halo/app/event/post/PostDeletedEvent.java b/api/src/main/java/run/halo/app/event/post/PostDeletedEvent.java new file mode 100644 index 000000000..7330f8efa --- /dev/null +++ b/api/src/main/java/run/halo/app/event/post/PostDeletedEvent.java @@ -0,0 +1,24 @@ +package run.halo.app.event.post; + +import run.halo.app.core.extension.content.Post; +import run.halo.app.plugin.SharedEvent; + +@SharedEvent +public class PostDeletedEvent extends PostEvent { + + private final Post post; + + public PostDeletedEvent(Object source, Post post) { + super(source, post.getMetadata().getName()); + this.post = post; + } + + /** + * Get original post. + * + * @return original post. + */ + public Post getPost() { + return post; + } +} diff --git a/api/src/main/java/run/halo/app/event/post/PostEvent.java b/api/src/main/java/run/halo/app/event/post/PostEvent.java new file mode 100644 index 000000000..1d672b220 --- /dev/null +++ b/api/src/main/java/run/halo/app/event/post/PostEvent.java @@ -0,0 +1,27 @@ +package run.halo.app.event.post; + +import org.springframework.context.ApplicationEvent; + +/** + * An abstract class for post events. + * + * @author johnniang + */ +public abstract class PostEvent extends ApplicationEvent { + + private final String name; + + public PostEvent(Object source, String name) { + super(source); + this.name = name; + } + + /** + * Gets post metadata name. + * + * @return post metadata name + */ + public String getName() { + return name; + } +} diff --git a/api/src/main/java/run/halo/app/event/post/PostPublishedEvent.java b/api/src/main/java/run/halo/app/event/post/PostPublishedEvent.java new file mode 100644 index 000000000..0c446d864 --- /dev/null +++ b/api/src/main/java/run/halo/app/event/post/PostPublishedEvent.java @@ -0,0 +1,12 @@ +package run.halo.app.event.post; + +import run.halo.app.plugin.SharedEvent; + +@SharedEvent +public class PostPublishedEvent extends PostEvent { + + public PostPublishedEvent(Object source, String postName) { + super(source, postName); + } + +} diff --git a/api/src/main/java/run/halo/app/event/post/PostUnpublishedEvent.java b/api/src/main/java/run/halo/app/event/post/PostUnpublishedEvent.java new file mode 100644 index 000000000..52c1c03e3 --- /dev/null +++ b/api/src/main/java/run/halo/app/event/post/PostUnpublishedEvent.java @@ -0,0 +1,12 @@ +package run.halo.app.event.post; + +import run.halo.app.plugin.SharedEvent; + +@SharedEvent +public class PostUnpublishedEvent extends PostEvent { + + public PostUnpublishedEvent(Object source, String postName) { + super(source, postName); + } + +} diff --git a/api/src/main/java/run/halo/app/event/post/PostUpdatedEvent.java b/api/src/main/java/run/halo/app/event/post/PostUpdatedEvent.java new file mode 100644 index 000000000..74c9123d5 --- /dev/null +++ b/api/src/main/java/run/halo/app/event/post/PostUpdatedEvent.java @@ -0,0 +1,12 @@ +package run.halo.app.event.post; + +import run.halo.app.plugin.SharedEvent; + +@SharedEvent +public class PostUpdatedEvent extends PostEvent { + + public PostUpdatedEvent(Object source, String postName) { + super(source, postName); + } + +} diff --git a/api/src/main/java/run/halo/app/event/post/PostVisibleChangedEvent.java b/api/src/main/java/run/halo/app/event/post/PostVisibleChangedEvent.java new file mode 100644 index 000000000..c3579f847 --- /dev/null +++ b/api/src/main/java/run/halo/app/event/post/PostVisibleChangedEvent.java @@ -0,0 +1,30 @@ +package run.halo.app.event.post; + +import org.springframework.lang.Nullable; +import run.halo.app.core.extension.content.Post; +import run.halo.app.plugin.SharedEvent; + +@SharedEvent +public class PostVisibleChangedEvent extends PostEvent { + + @Nullable + private final Post.VisibleEnum oldVisible; + + private final Post.VisibleEnum newVisible; + + public PostVisibleChangedEvent(Object source, String postName, + @Nullable Post.VisibleEnum oldVisible, Post.VisibleEnum newVisible) { + super(source, postName); + this.oldVisible = oldVisible; + this.newVisible = newVisible; + } + + @Nullable + public Post.VisibleEnum getOldVisible() { + return oldVisible; + } + + public Post.VisibleEnum getNewVisible() { + return newVisible; + } +} diff --git a/application/src/main/java/run/halo/app/plugin/SharedEvent.java b/api/src/main/java/run/halo/app/plugin/SharedEvent.java similarity index 82% rename from application/src/main/java/run/halo/app/plugin/SharedEvent.java rename to api/src/main/java/run/halo/app/plugin/SharedEvent.java index 3174c5e43..a62026c9d 100644 --- a/application/src/main/java/run/halo/app/plugin/SharedEvent.java +++ b/api/src/main/java/run/halo/app/plugin/SharedEvent.java @@ -9,8 +9,7 @@ import java.lang.annotation.Target; /** *
It is a symbolic annotation.
*When the event marked with {@link SharedEvent} annotation is published, it will be - * broadcast to the application context of the plugin by - * {@link PluginApplicationEventBridgeDispatcher}.
+ * broadcast to the application context of the plugin. * * @author guqing * @since 2.0.0 diff --git a/application/src/main/java/run/halo/app/core/extension/reconciler/PostReconciler.java b/application/src/main/java/run/halo/app/core/extension/reconciler/PostReconciler.java index 3aa197002..2c36d022b 100644 --- a/application/src/main/java/run/halo/app/core/extension/reconciler/PostReconciler.java +++ b/application/src/main/java/run/halo/app/core/extension/reconciler/PostReconciler.java @@ -15,6 +15,7 @@ import com.google.common.hash.Hashing; import java.time.Duration; import java.time.Instant; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -88,7 +89,7 @@ public class PostReconciler implements Reconciler