Skip to content

Commit

Permalink
feat: add document for notification
Browse files Browse the repository at this point in the history
  • Loading branch information
guqing committed Oct 31, 2024
1 parent c03925c commit 379bf54
Show file tree
Hide file tree
Showing 6 changed files with 958 additions and 48 deletions.
475 changes: 475 additions & 0 deletions docs/developer-guide/plugin/api-reference/server/notification.md

Large diffs are not rendered by default.

27 changes: 3 additions & 24 deletions docs/developer-guide/plugin/basics/server/object-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,37 +102,16 @@ API 参考:[PostContentService](https://github.com/halo-dev/halo/blob/25086ee3

用于发送通知事件的 Bean。

#### 使用示例

假如有一个 `NEW_COMMENT_ON_POST` 文章有新评论的通知事件,你可以这样发送通知:

```java
Mono<Void> emitNewCommentOnPostReason(/* 此示例省略参数 */) {
return notificationReasonEmitter.emit(NotificationReasonConst.NEW_COMMENT_ON_POST,
builder -> {
// 填充事件的数据
var attributes = CommentOnPostReasonData.builder()
.postName(subjectRef.getName())
.postOwner(post.getSpec().getOwner())
.postTitle(post.getSpec().getTitle())
.postUrl(postUrl)
.commenter(owner.getDisplayName())
.content(comment.getSpec().getContent())
.commentName(comment.getMetadata().getName())
.build();
builder.attributes(ReasonDataConverter.toAttributeMap(attributes))
.author(identityFrom(owner))
.subject(reasonSubject);
})
}
```
使用示例参考 [通知事件触发示例](../../api-reference/server/notification.md#reason-emitter-example)

API 参考:[NotificationReasonEmitter](https://github.com/halo-dev/halo/blob/25086ee3e63f0c8b6ed380140a068c44404ef2b2/api/src/main/java/run/halo/app/notification/NotificationReasonEmitter.java)

### NotificationCenter

用于管理通知的订阅和取消订阅。

使用示例参考 [通知订阅示例](../../api-reference/server/notification.md#subscribe-example)

API 参考:[NotificationCenter](https://github.com/halo-dev/halo/blob/25086ee3e63f0c8b6ed380140a068c44404ef2b2/api/src/main/java/run/halo/app/notification/NotificationCenter.java)

### ExternalLinkProcessor
Expand Down
1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ module.exports = {
"developer-guide/plugin/api-reference/server/extension-client",
"developer-guide/plugin/api-reference/server/setting-fetcher",
"developer-guide/plugin/api-reference/server/reverseproxy",
"developer-guide/plugin/api-reference/server/notification",
"developer-guide/plugin/api-reference/server/finder-for-theme",
"developer-guide/plugin/api-reference/server/template-for-theme",
"developer-guide/plugin/api-reference/server/websocket",
Expand Down
Loading

0 comments on commit 379bf54

Please sign in to comment.