package notify // import "git.griefed.de/griefed/repoman/internal/notify"
Package notify is the single entry point for raising a user notification:
it records an in-app notification (the source of truth) and, when SMTP is
configured, also emails a copy. Callers don't branch on whether email is on.
TYPES
type Mailer interface {
IsConfigured() bool
SendNotification(ctx context.Context, toAddress, title, body, link string) error
}
Mailer sends a notification email. email.Sender satisfies it; a nil or
unconfigured Mailer makes the email channel a no-op.
type NoteCreator interface {
Create(ctx context.Context, note *db.Notification) (int64, error)
}
NoteCreator persists an in-app notification. db.NotificationRepo satisfies
it.
type Service struct {
Notes NoteCreator
Mailer Mailer
Users UserLookup
// BaseURL is the externally-visible instance URL used to make email links
// absolute (e.g. "https://repoman.example.com"). Empty leaves links relative.
BaseURL string
}
Service raises notifications across the in-app and email channels.
func (s *Service) Notify(ctx context.Context, userID int64, kind, title, body, link string) error
Notify records an in-app notification for userID and, best-effort, emails a
copy when SMTP is configured. It returns an error only when the in-app write
(the source of truth) fails; email failures are logged, not returned.
func (s *Service) NotifyUsers(ctx context.Context, userIDs []int64, kind, title, body, link string)
NotifyUsers raises the same notification for each user id, logging (not
failing) on a per-user in-app error so one bad recipient doesn't drop the
rest.
type UserLookup interface {
GetByID(ctx context.Context, userID int64) (*auth.User, error)
}
UserLookup resolves a user (for their email). db.UserRepo satisfies it.