NewStoreEnqueuer creates an Enqueuer implementation which can persist notification messages in the store.
(cfg codersdk.NotificationsConfig, store Store, helpers template.FuncMap, log slog.Logger, clock quartz.Clock)
| 50 | |
| 51 | // NewStoreEnqueuer creates an Enqueuer implementation which can persist notification messages in the store. |
| 52 | func NewStoreEnqueuer(cfg codersdk.NotificationsConfig, store Store, helpers template.FuncMap, log slog.Logger, clock quartz.Clock) (*StoreEnqueuer, error) { |
| 53 | var method database.NotificationMethod |
| 54 | // TODO(DanielleMaywood): |
| 55 | // Currently we do not want to allow setting `inbox` as the default notification method. |
| 56 | // As of 2025-03-25, setting this to `inbox` would cause a crash on the deployment |
| 57 | // notification settings page. Until we make a future decision on this we want to disallow |
| 58 | // setting it. |
| 59 | if err := method.Scan(cfg.Method.String()); err != nil || method == database.NotificationMethodInbox { |
| 60 | return nil, InvalidDefaultNotificationMethodError{Method: cfg.Method.String()} |
| 61 | } |
| 62 | |
| 63 | return &StoreEnqueuer{ |
| 64 | store: store, |
| 65 | log: log, |
| 66 | defaultMethod: method, |
| 67 | defaultEnabled: cfg.Enabled(), |
| 68 | inboxEnabled: cfg.Inbox.Enabled.Value(), |
| 69 | helpers: helpers, |
| 70 | clock: clock, |
| 71 | }, nil |
| 72 | } |
| 73 | |
| 74 | // Enqueue queues a notification message for later delivery, assumes no structured input data. |
| 75 | // Returns the IDs of successfully enqueued messages, if any. |