app

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

This section is empty.

Types

type Clock

type Clock func() time.Time

type EmailSender

type EmailSender interface {
	SendLoginCode(ctx context.Context, to, code string) error
	SendInvite(ctx context.Context, to, workspaceName, invitationID string) error
	Send(ctx context.Context, to, subject, body string) error
}

type Notification

type Notification struct {
	ID        string     `json:"id"`
	Type      string     `json:"type"`
	Title     string     `json:"title"`
	Body      string     `json:"body"`
	Link      string     `json:"link,omitempty"`
	Workspace string     `json:"workspace_id,omitempty"`
	Count     int        `json:"count"`
	ReadAt    *time.Time `json:"read_at,omitempty"`
	CreatedAt time.Time  `json:"created_at"`
}

type NotifyInput

type NotifyInput struct {
	UserID string
	Type   string
	Title  string
	Body   string
	Link   string

	// Workspace is the optional workspace dimension (F8): empty = user-global
	// notification (the framework bell model); set = the notification belongs to
	// that workspace's scoped inbox. Note dedup: uq_notification_dedup keys on
	// (user_id, dedup_key) — per-workspace dedup requires the workspace id inside
	// the DedupKey itself.
	Workspace string

	DedupKey string

	OncePerMonth bool
}

type NotifyService

type NotifyService struct {
	// contains filtered or unexported fields
}

func NewNotifyService

func NewNotifyService(repo Repo, mail EmailSender, now Clock) *NotifyService

func (*NotifyService) Archive

func (s *NotifyService) Archive(ctx context.Context, userID, id string) error

func (*NotifyService) Badge

func (s *NotifyService) Badge(ctx context.Context, userID, workspaceID string) (int, error)

func (*NotifyService) Inbox

func (s *NotifyService) Inbox(ctx context.Context, userID, workspaceID string, limit int) ([]Notification, error)

func (*NotifyService) ListPreferences

func (s *NotifyService) ListPreferences(ctx context.Context, userID string) ([]Preference, error)

func (*NotifyService) MarkAllRead

func (s *NotifyService) MarkAllRead(ctx context.Context, userID string) error

func (*NotifyService) MarkRead

func (s *NotifyService) MarkRead(ctx context.Context, userID, id string) error

func (*NotifyService) Notify

func (s *NotifyService) Notify(ctx context.Context, input NotifyInput) error

func (*NotifyService) NotifyOncePerMonth

func (s *NotifyService) NotifyOncePerMonth(ctx context.Context, input NotifyInput) error

func (*NotifyService) SendEmail

func (s *NotifyService) SendEmail(ctx context.Context, to, subject, body string) error

func (*NotifyService) SendTypeEmail

func (s *NotifyService) SendTypeEmail(ctx context.Context, userID, typ, to, subject, body string) error

func (*NotifyService) UpsertPreference

func (s *NotifyService) UpsertPreference(ctx context.Context, userID, typ string, email, inApp *bool) (Preference, error)

func (*NotifyService) WithPrefGate

func (s *NotifyService) WithPrefGate(gate PrefGate) *NotifyService

type PrefGate

type PrefGate interface {
	List(ctx context.Context, userID string) ([]Preference, error)

	Upsert(ctx context.Context, userID, typ string, email, inApp *bool) (Preference, error)

	Allowed(ctx context.Context, userID, typ string) (bool, error)

	EmailAllowed(ctx context.Context, userID, typ string) (bool, error)
}

type Preference

type Preference struct {
	NotificationType string    `json:"notification_type"`
	EmailEnabled     bool      `json:"email_enabled"`
	InAppEnabled     bool      `json:"in_app_enabled"`
	UpdatedAt        time.Time `json:"updated_at"`
}

type Repo

type Repo interface {
	Insert(ctx context.Context, n NotifyInput, now time.Time) (isNew bool, err error)

	// ListInbox / UnreadCount take an optional workspaceID filter: empty lists the
	// whole user inbox (bell semantics), non-empty restricts to that workspace.
	ListInbox(ctx context.Context, userID, workspaceID string, limit int) ([]Notification, error)

	UnreadCount(ctx context.Context, userID, workspaceID string) (int, error)

	MarkRead(ctx context.Context, userID, notificationID string) error
	MarkAllRead(ctx context.Context, userID string) error

	Archive(ctx context.Context, userID, notificationID string) error
}

Jump to

Keyboard shortcuts

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