mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
feat(coderd): add inbox notifications endpoints (#16889)
This PR is part of the inbox notifications topic, and rely on previous PRs merged - it adds : - Endpoints to : - WS : watch new inbox notifications - REST : list inbox notifications - REST : update the read status of a notification Also, this PR acts as a follow-up PR from previous work and : - fix DB query issues - fix DBMem logic to match DB
This commit is contained in:
43
coderd/pubsub/inboxnotification.go
Normal file
43
coderd/pubsub/inboxnotification.go
Normal file
@ -0,0 +1,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"
|
||||
)
|
Reference in New Issue
Block a user