MCPcopy Index your code
hub / github.com/coder/coder / dispatch

Method dispatch

coderd/notifications/dispatch/inbox.go:39–104  ·  view source on GitHub ↗
(payload types.MessagePayload, title, body string)

Source from the content-addressed store, hash-verified

37}
38
39func (s *InboxHandler) dispatch(payload types.MessagePayload, title, body string) DeliveryFunc {
40 return func(ctx context.Context, msgID uuid.UUID) (bool, error) {
41 userID, err := uuid.Parse(payload.UserID)
42 if err != nil {
43 return false, xerrors.Errorf("parse user ID: %w", err)
44 }
45 templateID, err := uuid.Parse(payload.NotificationTemplateID)
46 if err != nil {
47 return false, xerrors.Errorf("parse template ID: %w", err)
48 }
49
50 actions, err := json.Marshal(payload.Actions)
51 if err != nil {
52 return false, xerrors.Errorf("marshal actions: %w", err)
53 }
54
55 // nolint:exhaustruct
56 insertedNotif, err := s.store.InsertInboxNotification(ctx, database.InsertInboxNotificationParams{
57 ID: msgID,
58 UserID: userID,
59 TemplateID: templateID,
60 Targets: payload.Targets,
61 Title: title,
62 Content: body,
63 Actions: actions,
64 CreatedAt: dbtime.Now(),
65 })
66 if err != nil {
67 return false, xerrors.Errorf("insert inbox notification: %w", err)
68 }
69
70 event := coderdpubsub.InboxNotificationEvent{
71 Kind: coderdpubsub.InboxNotificationEventKindNew,
72 InboxNotification: codersdk.InboxNotification{
73 ID: msgID,
74 UserID: userID,
75 TemplateID: templateID,
76 Targets: payload.Targets,
77 Title: title,
78 Content: body,
79 Actions: func() []codersdk.InboxNotificationAction {
80 var actions []codersdk.InboxNotificationAction
81 err := json.Unmarshal(insertedNotif.Actions, &actions)
82 if err != nil {
83 return actions
84 }
85 return actions
86 }(),
87 ReadAt: nil, // notification just has been inserted
88 CreatedAt: insertedNotif.CreatedAt,
89 },
90 }
91
92 payload, err := json.Marshal(event)
93 if err != nil {
94 return false, xerrors.Errorf("marshal event: %w", err)
95 }
96

Callers 1

DispatcherMethod · 0.95

Calls 7

NowFunction · 0.92
ParseMethod · 0.65
PublishMethod · 0.65
ErrorfMethod · 0.45
MarshalMethod · 0.45
UnmarshalMethod · 0.45

Tested by

no test coverage detected