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

Function convertInboxNotificationResponse

coderd/inboxnotifications.go:77–104  ·  view source on GitHub ↗

convertInboxNotificationResponse works as a util function to transform a database.InboxNotification to codersdk.InboxNotification

(ctx context.Context, logger slog.Logger, notif database.InboxNotification)

Source from the content-addressed store, hash-verified

75
76// convertInboxNotificationResponse works as a util function to transform a database.InboxNotification to codersdk.InboxNotification
77func convertInboxNotificationResponse(ctx context.Context, logger slog.Logger, notif database.InboxNotification) codersdk.InboxNotification {
78 convertedNotif := codersdk.InboxNotification{
79 ID: notif.ID,
80 UserID: notif.UserID,
81 TemplateID: notif.TemplateID,
82 Targets: notif.Targets,
83 Title: notif.Title,
84 Content: notif.Content,
85 Icon: notif.Icon,
86 Actions: func() []codersdk.InboxNotificationAction {
87 var actionsList []codersdk.InboxNotificationAction
88 err := json.Unmarshal([]byte(notif.Actions), &actionsList)
89 if err != nil {
90 logger.Error(ctx, "unmarshal inbox notification actions", slog.Error(err))
91 }
92 return actionsList
93 }(),
94 ReadAt: func() *time.Time {
95 if !notif.ReadAt.Valid {
96 return nil
97 }
98 return &notif.ReadAt.Time
99 }(),
100 CreatedAt: notif.CreatedAt,
101 }
102
103 return ensureNotificationIcon(convertedNotif)
104}
105
106// watchInboxNotifications watches for new inbox notifications and sends them to the client.
107// The client can specify a list of target IDs to filter the notifications.

Callers 2

Calls 3

ensureNotificationIconFunction · 0.85
UnmarshalMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected