webpush

package
v1.4.0 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: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configure

func Configure(c Config)

func DeletePushSubscription

func DeletePushSubscription(userID int64, endpoint string) error

DeletePushSubscription removes one subscription by endpoint - called when the browser reports the subscription as no longer valid, or the user explicitly turns push off on that device.

func GetVAPIDPublicKey

func GetVAPIDPublicKey() (string, error)

GetVAPIDPublicKey returns the raw (uncompressed point) VAPID public key, base64url-encoded for use as a PushManager applicationServerKey. Keys are generated on first use and stored in business_config, the private half encrypted at rest the same way payment-provider secrets are (see secretStoreConfigKeys in services/config.go).

func SavePushSubscription

func SavePushSubscription(userID int64, endpoint, p256dh, auth, userAgent string) error

SavePushSubscription upserts a subscription by its endpoint - re-subscribing the same browser (e.g. after clearing site data reissues the same endpoint in some browsers, or a plain re-registration) just refreshes the row instead of accumulating duplicates.

func SendSessionEndedPush

func SendSessionEndedPush(userID int64)

SendSessionEndedPush tells every device userID has subscribed that their session was just killed server-side (account disabled or deleted - see handleAdminUserUpdate/handleAdminUserDelete) so an open tab can prompt an in-place reauth instead of the next click just silently failing. Carries no title/body: the service worker only forwards this kind to a visible tab's page script (see sw.js) and never surfaces it as an OS notification, since there's nothing for a closed tab to usefully show.

func SendWebPushToUser

func SendWebPushToUser(userID int64, title, body, link string, unreadCount *int64)

SendWebPushToUser encrypts and delivers title/body (already localized plain text - a service worker has no i18n framework to hand a key to) to every device userID has subscribed. Dead subscriptions (410 Gone / 404 Not Found, meaning the browser or OS discarded the registration) are pruned as they're discovered rather than retried forever.

func UserHasPushSubscription

func UserHasPushSubscription(userID int64) bool

UserHasPushSubscription reports whether userID has at least one registered device - used to skip the work of building a push payload for users who have never enabled it.

Types

type Config

type Config struct {
	DB              func() *sql.DB
	MySQL           bool
	GetSetting      func(key string) (string, error)
	SetSetting      func(key, value string) error
	InstanceURL     func() string
	FallbackSubject string
}

type PushSubscription

type PushSubscription struct {
	ID        int64  `db:"id"`
	UserID    int64  `db:"user_id"`
	Endpoint  string `db:"endpoint"`
	P256dh    string `db:"p256dh"`
	Auth      string `db:"auth"`
	UserAgent string `db:"user_agent"`
}

PushSubscription is one browser/device's Web Push registration.

Jump to

Keyboard shortcuts

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