notifications

package
v0.0.201 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2026 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const SchedulerTaskName = "digest_scheduler"

Variables

This section is empty.

Functions

func EmailHTMLTemplateFilenameGenerator

func EmailHTMLTemplateFilenameGenerator(base string) string

func EmailSubjectTemplateFilenameGenerator

func EmailSubjectTemplateFilenameGenerator(base string) string

func EmailTextTemplateFilenameGenerator

func EmailTextTemplateFilenameGenerator(base string) string

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.

func NotificationTemplateFilenameGenerator

func NotificationTemplateFilenameGenerator(base string) string

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 EmailData

type EmailData struct {
	URL            string
	SubjectPrefix  string
	UnsubscribeUrl string
	SignOff        string
	SignOffHTML    htemplate.HTML
	Item           interface{}
	Recipient      *db.SystemGetUserByIDRow
	// contains filtered or unexported fields
}

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

type EmailTemplates struct {
	Text    string
	HTML    string
	Subject string
}

func NewEmailTemplates

func NewEmailTemplates(prefix string) *EmailTemplates

NewEmailTemplates returns EmailTemplates populated with file names derived from prefix.

type GrantRequirement

type GrantRequirement struct {
	Section string
	Item    string
	ItemID  int32
	Action  string
}

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 New

func New(opts ...Option) *Notifier

New constructs a Notifier with the provided dependencies.

func (*Notifier) BusWorker

func (n *Notifier) BusWorker(ctx context.Context, bus *eventbus.Bus, q dlq.DLQ)

func (*Notifier) NotifyAdmins

func (n *Notifier) NotifyAdmins(ctx context.Context, et *EmailTemplates, data EmailData) error

NotifyAdmins sends a generic update notice to administrator accounts.

func (*Notifier) ProcessDigestForTime

func (n *Notifier) ProcessDigestForTime(ctx context.Context, t time.Time)

ProcessDigestForTime is called by the consumer to process digests for a specific time. It was previously private `processDigestForTime`.

func (*Notifier) ProcessEvent

func (n *Notifier) ProcessEvent(ctx context.Context, evt eventbus.TaskEvent, q dlq.DLQ) error

func (*Notifier) PurgeReadNotifications

func (n *Notifier) PurgeReadNotifications(ctx context.Context, t time.Time) error

PurgeReadNotifications removes old read notifications.

func (*Notifier) RegisterSync

func (n *Notifier) RegisterSync(bus *eventbus.Bus, q dlq.DLQ)

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

func (n *Notifier) ScheduleDigest(ctx context.Context, t time.Time) error

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 WithBus

func WithBus(b *eventbus.Bus) Option

WithBus sets the event bus dependency used to publish email queue events.

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

func WithEmailProvider(p email.Provider) Option

WithEmailProvider sets the email provider dependency.

func WithQueries

func WithQueries(q db.Querier) Option

WithQueries sets the db.Queries dependency.

func WithSilence

func WithSilence(silent bool) Option

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

type Target struct {
	Type string
	ID   int32
}

Target references a specific item for subscription notifications.

func (Target) SubscriptionTarget

func (t Target) SubscriptionTarget() (string, int32)

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.

type TemplateEngine

type TemplateEngine interface {
	ExecuteTemplate(wr io.Writer, name string, data any) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL