/
driver_notification.go
59 lines (46 loc) · 1.58 KB
/
driver_notification.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
49
50
51
52
53
54
55
56
57
58
59
package bertybridge
import (
"time"
"go.uber.org/zap"
"berty.tech/berty/v2/go/internal/logutil"
"berty.tech/berty/v2/go/internal/notification"
)
type NotificationDriver interface {
Post(notif *LocalNotification) error
}
// noopNotificationDriver is NotificationDriver
var _ NotificationDriver = (*noopNotificationDriver)(nil)
type noopNotificationDriver struct{}
func (*noopNotificationDriver) Post(*LocalNotification) error { return nil }
type notificationManagerAdapter struct {
logger *zap.Logger
driver NotificationDriver
}
// notificationManagerAdapter is a NotificationManager
var _ notification.Manager = (*notificationManagerAdapter)(nil)
func newNotificationManagerAdapter(logger *zap.Logger, driver NotificationDriver) notification.Manager {
return ¬ificationManagerAdapter{logger, driver}
}
func (a *notificationManagerAdapter) Notify(notif *notification.Notification) error {
a.logger.Debug("notification triggered",
logutil.PrivateString("title", notif.Title), logutil.PrivateString("body", notif.Body))
return a.driver.Post(&LocalNotification{
Title: notif.Title,
Body: notif.Body,
Interval: 0.0,
})
}
func (a *notificationManagerAdapter) Schedule(notif *notification.Notification, interval time.Duration) error {
a.logger.Debug("notification scheduled",
logutil.PrivateString("title", notif.Title), logutil.PrivateString("body", notif.Body))
return a.driver.Post(&LocalNotification{
Title: notif.Title,
Body: notif.Body,
Interval: interval.Seconds(),
})
}
type LocalNotification struct {
Title string
Body string
Interval float64
}