convertInboxNotificationResponse works as a util function to transform a database.InboxNotification to codersdk.InboxNotification
(ctx context.Context, logger slog.Logger, notif database.InboxNotification)
| 75 | |
| 76 | // convertInboxNotificationResponse works as a util function to transform a database.InboxNotification to codersdk.InboxNotification |
| 77 | func 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 ¬if.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. |
no test coverage detected