feat: 文章锁定/解锁时触发系统通知
- 新增 NotifyPostLocked/NotifyPostUnlocked 通知类型 - Lock/Unlock 方法执行后通过 notifier 发送通知给作者 - 锁定时通知含锁定理由,解锁时通知已解除锁定 - 新增类型归入稿件审核分类和 system tab
This commit is contained in:
@ -47,7 +47,7 @@ func countUIDs(uids string) int {
|
||||
func categoryTypes(category string) []string {
|
||||
switch category {
|
||||
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":
|
||||
return []string{model.NotifyComment, model.NotifyCommentReply}
|
||||
case "like":
|
||||
@ -111,6 +111,24 @@ func (s *NotificationService) NotifyPostRejected(userID uint, postTitle, reason
|
||||
_ = 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)
|
||||
func (s *NotificationService) NotifyFollow(followerID, followeeID uint) {
|
||||
// 获取关注者用户名
|
||||
|
||||
@ -163,7 +163,14 @@ func (s *PostService) Lock(postID uint, reason string) error {
|
||||
}
|
||||
post.IsLocked = true
|
||||
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 标志,恢复可编辑
|
||||
@ -177,7 +184,14 @@ func (s *PostService) Unlock(postID uint) error {
|
||||
}
|
||||
post.IsLocked = false
|
||||
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 恢复软删除
|
||||
|
||||
@ -75,6 +75,8 @@ type userExpReader interface {
|
||||
type postNotifier interface {
|
||||
NotifyPostApproved(userID uint, postTitle 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 所需的用户仓储接口
|
||||
|
||||
Reference in New Issue
Block a user