Skip to content

Commit

Permalink
feat(notify): add notify_pending config option (#728) (#754)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwqcode authored Jan 29, 2024
1 parent a40a070 commit a7c3f1b
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions conf/artalk.example.simple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ email:
account_name: "[email protected]"
admin_notify:
notify_tpl: "default"
notify_pending: false
noise_mode: false
email:
enabled: true
Expand Down
2 changes: 2 additions & 0 deletions conf/artalk.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ email:
admin_notify:
# Notification template (set to file path to use custom template)
notify_tpl: "default"
# Pending comment still send notification (notifications are still sent when comments are intercepted)
notify_pending: false
# Noise mode
# -- noise_mode is disabled by default. --
# -- When this option is set to `false`, only messages sent to the administrator will be notified, --
Expand Down
2 changes: 2 additions & 0 deletions conf/artalk.example.zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ email:
admin_notify:
# 通知模版 (填入文件路径使用自定义模板)
notify_tpl: "default"
# 待审评论仍然发送通知 (当评论被拦截时仍然发送通知)
notify_pending: false
# 嘈杂模式
noise_mode: false
# 邮件通知管理员
Expand Down
11 changes: 10 additions & 1 deletion docs/docs/guide/backend/admin_notify.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,23 @@ admin_notify:
可用变量和邮件模板相同,可参考:[邮件模版](./email.md#邮件模板)
## 待审评论仍然发送通知 `notify_pending`
```yaml
admin_notify:
notify_pending: false
```

`notify_pending` 默认为关闭状态,当该项设置为 `false` 时,待审评论不会发送通知。你可以在控制中心查看所有待审核的评论。

## 嘈杂模式 `noise_mode`

```yaml
admin_notify:
noise_mode: false
```
noise_mode 默认为关闭状态,当该项设置为 `false` 时,站内仅向管理员回复的消息会发送通知,例如「普通用户 A」回复「普通用户 B」,这两个用户之间的通讯不会通知管理员。
`noise_mode` 默认为关闭状态,当该项设置为 `false` 时,站内仅向管理员回复的消息会发送通知,例如「普通用户 A」回复「普通用户 B」,这两个用户之间的通讯不会通知管理员。

注:当 `moderator.pending_default` 为 `true` 时,noise_mode 为始终开启状态。

Expand Down
1 change: 1 addition & 0 deletions i18n/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Password update failed":
"Password updated":
"Password":
"Pending":
"Please review":
"Retype {{name}}":
"Save failed":
Expand Down
1 change: 1 addition & 0 deletions i18n/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Password update failed": 密码修改失败
"Password updated": 密码已修改
"Password": 密码
"Pending": 待审核
"Please review": 请过目
"Retype {{name}}": 重新输入{{name}}
"Save failed": 保存失败
Expand Down
1 change: 1 addition & 0 deletions i18n/zh-TW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Password update failed": 密碼修改失敗
"Password updated": 密碼已修改
"Password": 密碼
"Pending": 待審核
"Please review": 請過目
"Retype {{name}}": 重新輸入{{name}}
"Save failed": 保存失敗
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ type AdminNotifyConf struct {
Slack NotifySlackConf `koanf:"slack" json:"slack"` // slack
LINE NotifyLINEConf `koanf:"line" json:"line"` // LINE
WebHook NotifyWebHookConf `koanf:"webhook" json:"webhook"` // WebHook
NotifyPending bool `koanf:"notify_pending" json:"notify_pending"` // 待审核评论通知
NoiseMode bool `koanf:"noise_mode" json:"noise_mode"` // 嘈杂模式 (非回复管理员的评论也发送通知)
}

Expand Down
10 changes: 10 additions & 0 deletions internal/notify_pusher/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func (pusher *NotifyPusher) checkNeedSendEmailToAdmin(comment *entity.Comment, p
return false
}

// 待审评论不发送通知
if comment.IsPending && !pusher.conf.NotifyPending {
return false
}

// 管理员自己回复自己,不提醒
if comment.UserID == admin.ID {
return false
Expand Down Expand Up @@ -73,6 +78,11 @@ func (pusher *NotifyPusher) checkNeedMultiPush(comment *entity.Comment, pComment
return false
}

// 待审评论不发送通知
if comment.IsPending && !pusher.conf.NotifyPending {
return false
}

// 非嘈杂模式
if !pusher.conf.NoiseMode {
// 如果不是 root 评论 且 回复目标不是管理员,直接忽略
Expand Down
1 change: 0 additions & 1 deletion internal/notify_pusher/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ func (pusher *NotifyPusher) sendEmail(notify *entity.Notify) {
if pusher.conf.EmailPush != nil {
pusher.conf.EmailPush(notify)
}
// email.AsyncSend(&notify)
}

func (pusher *NotifyPusher) emailToUser(comment *entity.Comment, pComment *entity.Comment) {
Expand Down
3 changes: 2 additions & 1 deletion internal/notify_pusher/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/ArtalkJS/Artalk/internal/entity"
"github.com/ArtalkJS/Artalk/internal/i18n"
"github.com/ArtalkJS/Artalk/internal/log"
"github.com/ArtalkJS/Artalk/internal/notify_pusher/sender"
"github.com/ArtalkJS/Artalk/internal/template"
Expand Down Expand Up @@ -65,7 +66,7 @@ func (pusher *NotifyPusher) getAdminNotifySubjectBody(comment *entity.Comment, t

body := render.Render(&notify)
if comment.IsPending {
body = "[待审状态评论]\n\n" + body
body = "[" + i18n.T("Pending") + "]\n\n" + body
}

return subject, body
Expand Down
3 changes: 1 addition & 2 deletions internal/notify_pusher/operate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
// 通知发送 (from comment to parentComment)
func (pusher *NotifyPusher) Push(comment *entity.Comment, pComment *entity.Comment) {
isRootComment := pComment == nil || pComment.IsEmpty()
isAdminNoiseModeOn := pusher.conf.NoiseMode

// ==============
// 邮件回复对方
Expand All @@ -19,7 +18,7 @@ func (pusher *NotifyPusher) Push(comment *entity.Comment, pComment *entity.Comme
// ==============
// 邮件通知管理员
// ==============
if isRootComment || isAdminNoiseModeOn {
if isRootComment || pusher.conf.NoiseMode {
pusher.emailToAdmins(comment, pComment)
}

Expand Down

0 comments on commit a7c3f1b

Please sign in to comment.