push

package
v0.17.4 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: AGPL-3.0 Imports: 41 Imported by: 0

Documentation

Overview

Package push manages Web Push subscriptions and delivers VAPID-signed notifications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolvePreferences added in v0.12.16

func ResolvePreferences(d settings.Document) map[marotte.PushKind]bool

ResolvePreferences resolves every registered kind's enabled flag from d: the per-kind toggles, then the master switch. A missing or undecodable value takes the kind's kindRegistry default.

Types

type KindPref

type KindPref struct {
	Kind        marotte.PushKind
	SettingsKey string
	DefaultOn   bool
}

KindPref is one registered kind. Exported so the settings write path can derive its preference map from this registry instead of keeping a third hand-maintained copy beside marotte.pushKinds.

func Kinds

func Kinds() []KindPref

Kinds returns the registered kinds and their settings keys. A caller wanting only the configurable ones filters on a non-empty SettingsKey. Returns a copy so no consumer can reorder or extend the registry.

type Option

type Option func(*Service)

Option configures a Service at construction.

func WithPresence

func WithPresence(p *Presence) Option

WithPresence wires the presence table the send filter reads. Absent, nothing is filtered and every subscription is pushed.

type Presence

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

Presence folds the hub's connected/disconnected feed and the client's keepalive acknowledgements into one verdict per client tag; Gone is what the send filter reads. The acknowledgement is the input the socket cannot supply: a locked phone's kernel keeps acknowledging while its page does not run, and a half-open peer stays connected for the kernel's whole retransmission budget.

Safe for concurrent use.

func NewPresence

func NewPresence() *Presence

NewPresence returns an empty table. Its windows are liveness.AliveWindow and liveness.ReconnectDelay, read at each verdict rather than copied in.

func (*Presence) Alive

func (p *Presence) Alive(tag string)

Alive records one keepalive acknowledgement for tag.

func (*Presence) AnyPresent added in v0.11.0

func (p *Presence) AnyPresent() bool

AnyPresent reports whether a page behind any tag is receiving the stream, by the verdict Gone reads.

func (*Presence) Gone

func (p *Presence) Gone(tag string) bool

Gone reports whether no page behind tag is receiving the stream: an unseen tag, a tag whose last connection departed more than one retry interval ago, or a connected tag silent for longer than the alive window.

func (*Presence) Observe

func (p *Presence) Observe(ev *sse.PresenceEvent)

Observe folds one hub event. Every disconnected cause is one departure whatever ended the socket: closed, dead, evicted, shutdown and hook_failed each follow exactly one connected, so the count balances only if all of them decrement. An event with no tag belongs to a client that presented none and is dropped.

type PresenceRow

type PresenceRow struct {
	LastAliveAt time.Time
	Tag         string
	Connected   int
	Gone        bool
}

PresenceRow is one tag's fold as the test-only probe reports it.

type Service

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

Service manages push subscriptions and sends notifications.

func New

func New(ctx context.Context, configDir, subject string, opts ...Option) *Service

New creates a Service, loads persisted subscriptions and preferences, and starts the write loop. subject is the VAPID subject. ctx is the service's lifetime and is required.

func (*Service) Close

func (s *Service) Close()

Close cancels in-flight pushes and waits for the write loop to drain pending saves.

func (*Service) HasSubscribers

func (s *Service) HasSubscribers() bool

HasSubscribers reports whether any push subscriptions are currently registered.

func (*Service) Preferences added in v0.12.16

func (s *Service) Preferences() map[marotte.PushKind]bool

Preferences returns a copy of the per-kind enabled flags the service enforces now.

func (*Service) PresenceRows

func (s *Service) PresenceRows() []PresenceRow

PresenceRows is the presence table as the test-only probe reports it; empty when no table is wired.

func (*Service) PresenceTransitions

func (s *Service) PresenceTransitions() (alive, expired uint64)

PresenceTransitions is the table's alive and expired counts; zero when no table is wired.

func (*Service) RegisterRoutes

func (s *Service) RegisterRoutes(mux *http.ServeMux)

RegisterRoutes wires /api/push/vapid-key, /api/push/subscribe, and /api/push/unsubscribe onto mux.

func (*Service) Retract

func (s *Service) Retract(subject marotte.PushSubject, ask string)

Retract drops the held ask push about subject that announces ask: the ask was answered on some surface, so a nudge about it has nothing left to say. A later ask's push and another kind's stay held. A no-op with the variant off, since nothing is ever held.

func (*Service) Send

func (s *Service) Send(ctx context.Context, sent *marotte.NotificationPayload)

Send delivers n to all subscribers, debounced per kind AND subject. The payload is n itself, so the service worker shows what the page would. preflightSend's nil means do not send; a non-nil empty slice has stamped the debounce.

func (*Service) SetPreferences

func (s *Service) SetPreferences(prefs map[marotte.PushKind]bool)

SetPreferences sets the enabled flag of each kind prefs names; a kind it omits keeps its flag.

func (*Service) Subscribe

func (s *Service) Subscribe(sub marotte.PushSubscription)

Subscribe registers a push subscription endpoint. Duplicate endpoints are silently overwritten.

func (*Service) Suppressed

func (s *Service) Suppressed(kind marotte.PushKind) uint64

Suppressed reports how many subscriptions the send filter skipped for kind since start.

func (*Service) Wants added in v0.11.0

func (s *Service) Wants(kind marotte.PushKind) bool

Wants reports whether a send of kind would pass the service's own gates: the service is healthy, the kind is registered and enabled, and a subscription exists to receive it. The presence filter is not consulted, because a profile that reads present is a reader rather than a reason to withhold the event.

Jump to

Keyboard shortcuts

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