@@ -21,23 +21,23 @@ import (
21
21
"github.com/coder/coder/v2/codersdk"
22
22
)
23
23
24
- //NotificationDispatcher is an interface that can be used to dispatch
25
- // push notifications.
26
- type NotificationDispatcher interface {
24
+ //Dispatcher is an interface that can be used to dispatch
25
+ // push notifications over Web Push .
26
+ type Dispatcher interface {
27
27
Dispatch (ctx context.Context ,userID uuid.UUID ,notification codersdk.WebpushMessage )error
28
28
PublicKey ()string
29
29
PrivateKey ()string
30
30
}
31
31
32
- // New creates a newpush manager to dispatchpush notifications.
32
+ // New creates a newDispatcher to dispatch notifications via Web Push .
33
33
//
34
34
// This is *not* integrated into the enqueue system unfortunately.
35
35
// That's because the notifications system has a enqueue system,
36
36
// and push notifications at time of implementation are being used
37
37
// for updates inside of a workspace, which we want to be immediate.
38
38
//
39
39
// See: https://github.com/coder/internal/issues/528
40
- func New (ctx context.Context ,log * slog.Logger ,db database.Store ) (NotificationDispatcher ,error ) {
40
+ func New (ctx context.Context ,log * slog.Logger ,db database.Store ) (Dispatcher ,error ) {
41
41
keys ,err := db .GetWebpushVAPIDKeys (ctx )
42
42
if err != nil {
43
43
if ! errors .Is (err ,sql .ErrNoRows ) {
@@ -57,23 +57,23 @@ func New(ctx context.Context, log *slog.Logger, db database.Store) (Notification
57
57
keys .VapidPrivateKey = newPrivateKey
58
58
}
59
59
60
- return & Notifier {
60
+ return & Webpusher {
61
61
store :db ,
62
62
log :log ,
63
63
VAPIDPublicKey :keys .VapidPublicKey ,
64
64
VAPIDPrivateKey :keys .VapidPrivateKey ,
65
65
},nil
66
66
}
67
67
68
- type Notifier struct {
68
+ type Webpusher struct {
69
69
store database.Store
70
70
log * slog.Logger
71
71
72
72
VAPIDPublicKey string
73
73
VAPIDPrivateKey string
74
74
}
75
75
76
- func (n * Notifier )Dispatch (ctx context.Context ,userID uuid.UUID ,notification codersdk.WebpushMessage )error {
76
+ func (n * Webpusher )Dispatch (ctx context.Context ,userID uuid.UUID ,notification codersdk.WebpushMessage )error {
77
77
subscriptions ,err := n .store .GetWebpushSubscriptionsByUserID (ctx ,userID )
78
78
if err != nil {
79
79
return xerrors .Errorf ("get notification push subscriptions by user ID: %w" ,err )
@@ -122,7 +122,7 @@ func (n *Notifier) Dispatch(ctx context.Context, userID uuid.UUID, notification
122
122
if resp .StatusCode > http .StatusAccepted {
123
123
// It's likely the subscription failed to deliver for some reason.
124
124
body ,_ := io .ReadAll (resp .Body )
125
- return xerrors .Errorf ("pushnotification failed with status code %d: %s" ,resp .StatusCode ,string (body ))
125
+ return xerrors .Errorf ("web pushdispatch failed with status code %d: %s" ,resp .StatusCode ,string (body ))
126
126
}
127
127
128
128
return nil
@@ -145,30 +145,30 @@ func (n *Notifier) Dispatch(ctx context.Context, userID uuid.UUID, notification
145
145
return nil
146
146
}
147
147
148
- func (n * Notifier )PublicKey ()string {
148
+ func (n * Webpusher )PublicKey ()string {
149
149
return n .VAPIDPublicKey
150
150
}
151
151
152
- func (n * Notifier )PrivateKey ()string {
152
+ func (n * Webpusher )PrivateKey ()string {
153
153
return n .VAPIDPrivateKey
154
154
}
155
155
156
- //NoopNotifier is aNotifier that does nothing except return an error.
156
+ //NoopWebpusher is aDispatcher that does nothing except return an error.
157
157
// This is returned when push notifications are disabled, or if there was an
158
158
// error generating the VAPID keys.
159
- type NoopNotifier struct {
159
+ type NoopWebpusher struct {
160
160
Msg string
161
161
}
162
162
163
- func (n * NoopNotifier )Dispatch (context.Context , uuid.UUID , codersdk.WebpushMessage )error {
163
+ func (n * NoopWebpusher )Dispatch (context.Context , uuid.UUID , codersdk.WebpushMessage )error {
164
164
return xerrors .New (n .Msg )
165
165
}
166
166
167
- func (* NoopNotifier )PublicKey ()string {
167
+ func (* NoopWebpusher )PublicKey ()string {
168
168
return ""
169
169
}
170
170
171
- func (* NoopNotifier )PrivateKey ()string {
171
+ func (* NoopWebpusher )PrivateKey ()string {
172
172
return ""
173
173
}
174
174