-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathinboxnotification.go
More file actions
43 lines (34 loc) · 1.14 KB
/
inboxnotification.go
File metadata and controls
43 lines (34 loc) · 1.14 KB
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
package pubsub
import (
"context"
"encoding/json"
"fmt"
"github.com/google/uuid"
"golang.org/x/xerrors"
"github.com/coder/coder/v2/codersdk"
)
func InboxNotificationForOwnerEventChannel(ownerID uuid.UUID) string {
return fmt.Sprintf("inbox_notification:owner:%s", ownerID)
}
func HandleInboxNotificationEvent(cb func(ctx context.Context, payload InboxNotificationEvent, err error)) func(ctx context.Context, message []byte, err error) {
return func(ctx context.Context, message []byte, err error) {
if err != nil {
cb(ctx, InboxNotificationEvent{}, xerrors.Errorf("inbox notification event pubsub: %w", err))
return
}
var payload InboxNotificationEvent
if err := json.Unmarshal(message, &payload); err != nil {
cb(ctx, InboxNotificationEvent{}, xerrors.Errorf("unmarshal inbox notification event"))
return
}
cb(ctx, payload, err)
}
}
type InboxNotificationEvent struct {
Kind InboxNotificationEventKind `json:"kind"`
InboxNotification codersdk.InboxNotification `json:"inbox_notification"`
}
type InboxNotificationEventKind string
const (
InboxNotificationEventKindNew InboxNotificationEventKind = "new"
)