Documentation
¶
Index ¶
- Constants
- func EmailHTMLTemplateFilenameGenerator(base string) string
- func EmailSubjectTemplateFilenameGenerator(base string) string
- func EmailTextTemplateFilenameGenerator(base string) string
- func GetUpdateEmailText(ctx context.Context, q db.Querier, cfg *config.RuntimeConfig, silent bool) string
- func NotificationTemplateFilenameGenerator(base string) string
- type AdminEmailTemplateProvider
- type AutoSubscribeProvider
- type DigestConsumer
- type DigestType
- type DirectEmailNotificationTemplateProvider
- type EmailData
- type EmailOption
- type EmailTemplateName
- type EmailTemplates
- type GrantRequirement
- type GrantsRequiredProvider
- type NewTemplateEngine
- type NotificationTemplateName
- type Notifier
- func (n *Notifier) BusWorker(ctx context.Context, bus *eventbus.Bus, q dlq.DLQ)
- func (n *Notifier) NotifyAdmins(ctx context.Context, et *EmailTemplates, data EmailData) error
- func (n *Notifier) ProcessDigestForTime(ctx context.Context, t time.Time)
- func (n *Notifier) ProcessEvent(ctx context.Context, evt eventbus.TaskEvent, q dlq.DLQ) error
- func (n *Notifier) PurgeReadNotifications(ctx context.Context, t time.Time) error
- func (n *Notifier) RegisterSync(bus *eventbus.Bus, q dlq.DLQ)
- func (n *Notifier) RenderEmailFromTemplates(ctx context.Context, emailAddr string, et *EmailTemplates, item interface{}, ...) ([]byte, error)
- func (n *Notifier) ScheduleDigest(ctx context.Context, t time.Time) error
- func (n *Notifier) SendDigestToUser(ctx context.Context, userID int32, email string, markRead, preview bool, ...) error
- type Option
- type SelfEmailBroadcaster
- type SelfNotificationTemplateProvider
- type SubscribersNotificationTemplateProvider
- type SubscriptionTarget
- type Target
- type TargetUsersNotificationProvider
- type TemplateEngine
Constants ¶
const SchedulerTaskName = "digest_scheduler"
Variables ¶
This section is empty.
Functions ¶
func GetUpdateEmailText ¶
func GetUpdateEmailText(ctx context.Context, q db.Querier, cfg *config.RuntimeConfig, silent bool) string
GetUpdateEmailText returns the update email text template after applying any database overrides.
Types ¶
type AdminEmailTemplateProvider ¶
type AdminEmailTemplateProvider interface {
AdminEmailTemplate(evt eventbus.TaskEvent) (templates *EmailTemplates, send bool)
AdminInternalNotificationTemplate(evt eventbus.TaskEvent) *string
}
AdminEmailTemplateProvider indicates the notification should be sent via email to administrators using the provided templates.
type AutoSubscribeProvider ¶
type AutoSubscribeProvider interface {
// AutoSubscribePath returns the action name and URI used when creating the
// subscription. The event may provide additional context required to build
// the path.
AutoSubscribePath(evt eventbus.TaskEvent) (string, string, error)
// AutoSubscribeGrants returns the permissions required to subscribe to the
// path.
AutoSubscribeGrants(evt eventbus.TaskEvent) ([]GrantRequirement, error)
}
AutoSubscribeProvider describes events that automatically create a subscription when user preferences allow.
type DigestConsumer ¶
type DigestConsumer struct {
// contains filtered or unexported fields
}
DigestConsumer consumes digest run events from the bus.
func NewDigestConsumer ¶
func NewDigestConsumer(n *Notifier) *DigestConsumer
NewDigestConsumer creates a new digest consumer.
func (*DigestConsumer) Run ¶
func (c *DigestConsumer) Run(ctx context.Context)
Run starts the consumer loop.
type DigestType ¶
type DigestType int
const ( DigestDaily DigestType = iota DigestWeekly DigestMonthly )
type DirectEmailNotificationTemplateProvider ¶
type DirectEmailNotificationTemplateProvider interface {
DirectEmailAddress(evt eventbus.TaskEvent) (string, error)
DirectEmailTemplate(evt eventbus.TaskEvent) (templates *EmailTemplates, send bool)
}
DirectEmailNotificationTemplateProvider specifies templates for an email sent directly to an address independent of the user's primary email. The address itself is obtained from the event data via DirectEmailAddress. Internal notifications are not supported for this provider.
type EmailOption ¶
type EmailOption func(*EmailData)
EmailOption configures EmailData prior to rendering.
func WithAdmin ¶
func WithAdmin() EmailOption
WithAdmin appends " Admin" to the subject prefix to flag administrative emails.
func WithRecipient ¶
func WithRecipient(u *db.SystemGetUserByIDRow) EmailOption
WithRecipient adds the recipient user to EmailData.
type EmailTemplateName ¶
type EmailTemplateName string
EmailTemplateName is a strongly-typed name for email templates (prefix).
func (EmailTemplateName) EmailTemplates ¶
func (e EmailTemplateName) EmailTemplates() *EmailTemplates
func (EmailTemplateName) NotificationTemplate ¶
func (e EmailTemplateName) NotificationTemplate() string
func (EmailTemplateName) RequiredTemplates ¶
func (e EmailTemplateName) RequiredTemplates() []tasks.Template
func (EmailTemplateName) String ¶
func (e EmailTemplateName) String() string
type EmailTemplates ¶
func NewEmailTemplates ¶
func NewEmailTemplates(prefix string) *EmailTemplates
NewEmailTemplates returns EmailTemplates populated with file names derived from prefix.
type GrantRequirement ¶
GrantRequirement describes a single permission check.
type GrantsRequiredProvider ¶
type GrantsRequiredProvider interface {
GrantsRequired(evt eventbus.TaskEvent) ([]GrantRequirement, error)
}
GrantsRequiredProvider exposes the permission context for subscription notifications. Implementations return one or more GrantRequirement values checked with `SystemCheckGrant` before delivering a message.
type NewTemplateEngine ¶
type NewTemplateEngine[TE TemplateEngine] interface { Parse(string) (TE, error) }
func HTMLTemplatesNew ¶
func HTMLTemplatesNew(s string) NewTemplateEngine[*htemplate.Template]
func TextTemplatesNew ¶
func TextTemplatesNew(s string) NewTemplateEngine[*ttemplate.Template]
type NotificationTemplateName ¶
type NotificationTemplateName string
NotificationTemplateName is a strongly-typed name for internal notification templates.
func (NotificationTemplateName) NotificationTemplate ¶
func (n NotificationTemplateName) NotificationTemplate() string
func (NotificationTemplateName) RequiredTemplates ¶
func (n NotificationTemplateName) RequiredTemplates() []tasks.Template
func (NotificationTemplateName) String ¶
func (n NotificationTemplateName) String() string
type Notifier ¶
type Notifier struct {
Bus *eventbus.Bus
EmailProvider email.Provider
Queries db.Querier
Config *config.RuntimeConfig
CustomQueries db.CustomQueries
Silent bool
// contains filtered or unexported fields
}
Notifier dispatches updates via email and internal notifications. Notifier dispatches updates via email and internal notifications.
func (*Notifier) NotifyAdmins ¶
NotifyAdmins sends a generic update notice to administrator accounts.
func (*Notifier) ProcessDigestForTime ¶
ProcessDigestForTime is called by the consumer to process digests for a specific time. It was previously private `processDigestForTime`.
func (*Notifier) ProcessEvent ¶
func (*Notifier) PurgeReadNotifications ¶
PurgeReadNotifications removes old read notifications.
func (*Notifier) RegisterSync ¶
RegisterSync configures the bus to deliver events synchronously to this notifier.
func (*Notifier) RenderEmailFromTemplates ¶
func (n *Notifier) RenderEmailFromTemplates(ctx context.Context, emailAddr string, et *EmailTemplates, item interface{}, opts ...EmailOption) ([]byte, error)
RenderEmailFromTemplates returns the rendered email message using the provided templates. Options may adjust the email metadata prior to rendering.
func (*Notifier) ScheduleDigest ¶
ScheduleDigest publishes a digest run event for the given time.
func (*Notifier) SendDigestToUser ¶
func (n *Notifier) SendDigestToUser(ctx context.Context, userID int32, email string, markRead, preview bool, dtype DigestType) error
SendDigestToUser sends a digest email.
type Option ¶
type Option func(*Notifier)
Option configures a Notifier instance.
func WithConfig ¶
func WithConfig(cfg *config.RuntimeConfig) Option
WithConfig derives dependencies from cfg when they are not supplied.
func WithCustomQueries ¶
func WithCustomQueries(cq db.CustomQueries) Option
WithCustomQueries sets the db.CustomQueries dependency.
func WithEmailProvider ¶
WithEmailProvider sets the email provider dependency.
func WithQueries ¶
WithQueries sets the db.Queries dependency.
func WithSilence ¶
WithSilence suppresses embedded template mode logging.
type SelfEmailBroadcaster ¶
type SelfEmailBroadcaster interface {
SelfEmailBroadcast() bool
}
SelfEmailBroadcaster indicates the notification should be sent to all verified email addresses of the user instead of only the highest priority.
type SelfNotificationTemplateProvider ¶
type SelfNotificationTemplateProvider interface {
SelfEmailTemplate(evt eventbus.TaskEvent) (templates *EmailTemplates, send bool)
SelfInternalNotificationTemplate(evt eventbus.TaskEvent) *string
}
SelfNotificationTemplateProvider is used for mandatory self notifications such as password resets or verifications.
type SubscribersNotificationTemplateProvider ¶
type SubscribersNotificationTemplateProvider interface {
SubscribedEmailTemplate(evt eventbus.TaskEvent) (templates *EmailTemplates, send bool)
SubscribedInternalNotificationTemplate(evt eventbus.TaskEvent) *string
}
SubscribersNotificationTemplateProvider indicates the notification should be delivered to subscribed users.
type SubscriptionTarget ¶
type SubscriptionTarget interface {
// SubscriptionTarget returns the item type and id used when building
// subscriptions and notifications.
SubscriptionTarget() (string, int32)
}
SubscriptionTarget exposes a subscribeable object.
type Target ¶
Target references a specific item for subscription notifications.
func (Target) SubscriptionTarget ¶
SubscriptionTarget implements SubscriptionTarget.
type TargetUsersNotificationProvider ¶
type TargetUsersNotificationProvider interface {
TargetUserIDs(evt eventbus.TaskEvent) ([]int32, error)
TargetEmailTemplate(evt eventbus.TaskEvent) (templates *EmailTemplates, send bool)
TargetInternalNotificationTemplate(evt eventbus.TaskEvent) *string
}
TargetUsersNotificationProvider indicates the notification should be delivered to the returned user IDs.