Documentation
¶
Overview ¶
Package push persists Web Push subscriptions + the in-app notification feed and delivers notifications to both. The VAPID key pair is generated once and stored alongside the subscriptions, so reinstalling the container keeps the browser subscriptions valid as long as the state dir survives.
Index ¶
- type Notification
- type Sender
- type Store
- func (s *Store) AddNotification(userID int, title, body, magnet string) error
- func (s *Store) Close()
- func (s *Store) DeleteEndpoint(endpoint string) error
- func (s *Store) LoadOrCreateVAPID() (publicKey, privateKey string, err error)
- func (s *Store) MarkAllRead(userID int) error
- func (s *Store) Notifications(userID, limit int) ([]Notification, error)
- func (s *Store) Subscribe(userID int, endpoint, p256dh, auth string) error
- func (s *Store) SubscriptionsFor(userID int) ([]Subscription, error)
- func (s *Store) UnreadCount(userID int) (int, error)
- func (s *Store) Unsubscribe(userID int, endpoint string) error
- type Subscription
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Notification ¶
type Notification struct {
ID int `json:"id"`
UserID int `json:"userId"`
Title string `json:"title"`
Body string `json:"body"`
Magnet string `json:"magnet,omitempty"`
Read bool `json:"read"`
CreatedAt time.Time `json:"createdAt"`
}
Notification is one entry of the in-app feed (the bell).
type Sender ¶
type Sender struct {
// contains filtered or unexported fields
}
Sender fans a notification out to the user's in-app feed and every Web Push subscription they registered. Failures are best-effort: a dead endpoint (404/410 from the push service) is dropped, anything else is just logged.
func (*Sender) NotifyUser ¶
NotifyUser records the notification in the in-app feed and pushes it to all of the user's browser subscriptions. The feed write is the source of truth — push delivery is opportunistic.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func New ¶
New wires the push store onto the shared Postgres pool. Schema is applied centrally (internal/db migrations).
func (*Store) AddNotification ¶
AddNotification appends to the in-app feed, trimming the oldest entries past maxFeedPerUser so the table can't grow unbounded.
func (*Store) Close ¶
func (s *Store) Close()
Close is a no-op: the shared pool's lifecycle is owned by main.
func (*Store) DeleteEndpoint ¶
DeleteEndpoint drops an endpoint regardless of owner — used when the push service reports it gone (404/410).
func (*Store) LoadOrCreateVAPID ¶
LoadOrCreateVAPID returns the persisted VAPID pair, generating it on first boot. Rotating the pair would invalidate every browser subscription, so it is generated exactly once.
func (*Store) MarkAllRead ¶
MarkAllRead flags the whole feed as read.
func (*Store) Notifications ¶
func (s *Store) Notifications(userID, limit int) ([]Notification, error)
Notifications returns the newest entries of the user's feed.
func (*Store) Subscribe ¶
Subscribe upserts a browser endpoint for the user. An endpoint that changes hands (browser profile re-login as another user) is re-owned, not duplicated.
func (*Store) SubscriptionsFor ¶
func (s *Store) SubscriptionsFor(userID int) ([]Subscription, error)
SubscriptionsFor lists the user's registered endpoints.
func (*Store) UnreadCount ¶
UnreadCount returns how many feed entries the user hasn't read.