feat: 文章锁定/解锁时触发系统通知

- 新增 NotifyPostLocked/NotifyPostUnlocked 通知类型
- Lock/Unlock 方法执行后通过 notifier 发送通知给作者
- 锁定时通知含锁定理由,解锁时通知已解除锁定
- 新增类型归入稿件审核分类和 system tab
This commit is contained in:
2026-06-02 22:53:46 +08:00
parent b0a1ff3c3f
commit ea2f196ff7
4 changed files with 43 additions and 3 deletions

View File

@ -6,6 +6,8 @@ const (
NotifyAuditRejected = "audit_rejected" NotifyAuditRejected = "audit_rejected"
NotifyPostApproved = "post_approved" NotifyPostApproved = "post_approved"
NotifyPostRejected = "post_rejected" NotifyPostRejected = "post_rejected"
NotifyPostLocked = "post_locked"
NotifyPostUnlocked = "post_unlocked"
NotifyLevelUp = "level_up" NotifyLevelUp = "level_up"
NotifyComment = "comment" NotifyComment = "comment"
NotifyCommentReply = "comment_reply" NotifyCommentReply = "comment_reply"
@ -32,6 +34,8 @@ var NotifyTypeNames = map[string]string{
NotifyAuditRejected: "资料审核", NotifyAuditRejected: "资料审核",
NotifyPostApproved: "稿件审核", NotifyPostApproved: "稿件审核",
NotifyPostRejected: "稿件审核", NotifyPostRejected: "稿件审核",
NotifyPostLocked: "稿件审核",
NotifyPostUnlocked: "稿件审核",
NotifyLevelUp: "等级提升", NotifyLevelUp: "等级提升",
NotifyComment: "评论", NotifyComment: "评论",
NotifyCommentReply: "回复", NotifyCommentReply: "回复",
@ -45,6 +49,8 @@ var NotifyCategory = map[string]string{
NotifyAuditRejected: "system", NotifyAuditRejected: "system",
NotifyPostApproved: "system", NotifyPostApproved: "system",
NotifyPostRejected: "system", NotifyPostRejected: "system",
NotifyPostLocked: "system",
NotifyPostUnlocked: "system",
NotifyLevelUp: "system", NotifyLevelUp: "system",
NotifyComment: "mention", NotifyComment: "mention",
NotifyCommentReply: "mention", NotifyCommentReply: "mention",

View File

@ -47,7 +47,7 @@ func countUIDs(uids string) int {
func categoryTypes(category string) []string { func categoryTypes(category string) []string {
switch category { switch category {
case "system": case "system":
return []string{model.NotifyAuditApproved, model.NotifyAuditRejected, model.NotifyPostApproved, model.NotifyPostRejected, model.NotifyLevelUp} return []string{model.NotifyAuditApproved, model.NotifyAuditRejected, model.NotifyPostApproved, model.NotifyPostRejected, model.NotifyPostLocked, model.NotifyPostUnlocked, model.NotifyLevelUp}
case "mention": case "mention":
return []string{model.NotifyComment, model.NotifyCommentReply} return []string{model.NotifyComment, model.NotifyCommentReply}
case "like": case "like":
@ -111,6 +111,24 @@ func (s *NotificationService) NotifyPostRejected(userID uint, postTitle, reason
_ = s.Create(userID, model.NotifyPostRejected, title, content, &postID, nil) _ = s.Create(userID, model.NotifyPostRejected, title, content, &postID, nil)
} }
// NotifyPostLocked 稿件锁定通知
func (s *NotificationService) NotifyPostLocked(userID uint, postTitle, reason string, postID uint) {
title := "稿件被锁定"
content := "你的稿件《" + postTitle + "》已被锁定"
if reason != "" {
content += ",理由:" + reason
}
_ = s.Create(userID, model.NotifyPostLocked, title, content, &postID, nil)
}
// NotifyPostUnlocked 稿件解除锁定通知
func (s *NotificationService) NotifyPostUnlocked(userID uint, postTitle string, postID uint) {
_ = s.Create(userID, model.NotifyPostUnlocked,
"稿件被解除锁定",
"你的稿件《"+postTitle+"》已被解除锁定",
&postID, nil)
}
// NotifyFollow 关注通知followerID 关注了 followeeID // NotifyFollow 关注通知followerID 关注了 followeeID
func (s *NotificationService) NotifyFollow(followerID, followeeID uint) { func (s *NotificationService) NotifyFollow(followerID, followeeID uint) {
// 获取关注者用户名 // 获取关注者用户名

View File

@ -163,7 +163,14 @@ func (s *PostService) Lock(postID uint, reason string) error {
} }
post.IsLocked = true post.IsLocked = true
post.LockReason = reason post.LockReason = reason
return s.repo.Update(post) if err := s.repo.Update(post); err != nil {
return err
}
// 通知作者稿件被锁定
if s.notifier != nil {
s.notifier.NotifyPostLocked(post.UserID, post.Title, reason, post.ID)
}
return nil
} }
// Unlock 解锁:清除 IsLocked 标志,恢复可编辑 // Unlock 解锁:清除 IsLocked 标志,恢复可编辑
@ -177,7 +184,14 @@ func (s *PostService) Unlock(postID uint) error {
} }
post.IsLocked = false post.IsLocked = false
post.LockReason = "" post.LockReason = ""
return s.repo.Update(post) if err := s.repo.Update(post); err != nil {
return err
}
// 通知作者稿件被解除锁定
if s.notifier != nil {
s.notifier.NotifyPostUnlocked(post.UserID, post.Title, post.ID)
}
return nil
} }
// Restore 恢复软删除 // Restore 恢复软删除

View File

@ -75,6 +75,8 @@ type userExpReader interface {
type postNotifier interface { type postNotifier interface {
NotifyPostApproved(userID uint, postTitle string, postID uint) NotifyPostApproved(userID uint, postTitle string, postID uint)
NotifyPostRejected(userID uint, postTitle, reason string, postID uint) NotifyPostRejected(userID uint, postTitle, reason string, postID uint)
NotifyPostLocked(userID uint, postTitle, reason string, postID uint)
NotifyPostUnlocked(userID uint, postTitle string, postID uint)
} }
// userLevelStore LevelService 所需的用户仓储接口 // userLevelStore LevelService 所需的用户仓储接口