/
service_notify.go
45 lines (36 loc) · 948 Bytes
/
service_notify.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
package core
import (
"github.com/ArtalkJS/Artalk/internal/entity"
"github.com/ArtalkJS/Artalk/internal/notify_pusher"
)
var _ Service = (*NotifyService)(nil)
type NotifyService struct {
app *App
pusher *notify_pusher.NotifyPusher
}
func NewNotifyService(app *App) *NotifyService {
return &NotifyService{app: app}
}
func (s *NotifyService) Init() error {
s.pusher = notify_pusher.NewNotifyPusher(¬ify_pusher.NotifyPusherConf{
AdminNotifyConf: s.app.Conf().AdminNotify,
Dao: s.app.Dao(),
EmailPush: func(notify *entity.Notify) error {
emailService, err := AppService[*EmailService](s.app)
if err != nil {
return err
}
emailService.AsyncSend(notify)
return nil
},
})
return nil
}
func (s *NotifyService) Dispose() error {
s.pusher = nil
return nil
}
func (s *NotifyService) Push(comment *entity.Comment, pComment *entity.Comment) error {
s.pusher.Push(comment, pComment)
return nil
}