-
-
Notifications
You must be signed in to change notification settings - Fork 141
/
email.go
48 lines (39 loc) · 1.37 KB
/
email.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package notify_pusher
import (
"github.com/ArtalkJS/Artalk/internal/entity"
"github.com/ArtalkJS/Artalk/internal/log"
"golang.org/x/exp/slices"
)
func (pusher *NotifyPusher) sendEmail(notify *entity.Notify) {
if pusher.conf.EmailPush != nil {
pusher.conf.EmailPush(notify)
}
}
func (pusher *NotifyPusher) emailToUser(comment *entity.Comment, pComment *entity.Comment) {
if !pusher.checkNeedSendEmailToUser(comment, pComment) {
log.Debug("ignore email notify by pusher.checkNeedSendEmailToUser")
return
}
notify := pusher.dao.FindCreateNotify(pComment.UserID, comment.ID)
pusher.dao.NotifySetInitial(¬ify)
// 邮件通知
pusher.sendEmail(¬ify)
}
func (pusher *NotifyPusher) emailToAdmins(comment *entity.Comment, pComment *entity.Comment) {
toAddrSent := []string{} // 记录已发送的收件人地址(避免重复发送)
for _, admin := range pusher.dao.GetAllAdmins() {
// 该管理员地址已曾发送,避免重复发送
if slices.Contains(toAddrSent, admin.Email) {
continue
}
toAddrSent = append(toAddrSent, admin.Email)
if !pusher.checkNeedSendEmailToAdmin(comment, pComment, &admin) {
log.Debug("ignore email notify by pusher.checkNeedSendEmailToAdmin")
continue
}
notify := pusher.dao.FindCreateNotify(admin.ID, comment.ID)
pusher.dao.NotifySetInitial(¬ify)
// 发送邮件给管理员
pusher.sendEmail(¬ify)
}
}