notify

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package notify decides, server-side, who gets a Web Push for a message or an alert (plan pipeline steps 6 and 7). In-app, browser and tray notifications are decided by the clients with the same pkg/notifyrules; the server only owns the case where no window is looking: it applies the rules to every channel member and hands the notifiable ones, who are not focused on a bubbles window, to the push sender.

Index

Constants

View Source
const FocusWindow = 60 * time.Second

FocusWindow is how recently a user must have had a visible, focused window for the server to hold back Web Push (plan pipeline step 7): the browser already shows the message, and a push on top of it would be noise. It covers the gap while a window is hidden, a device sleeps or a socket reconnects.

View Source
const QueueSize = 10000

QueueSize bounds the events waiting for the dispatcher. The writer goroutine never waits for it: when the queue is full an event is dropped and counted (a missed push is better than a stalled write path).

Variables

This section is empty.

Functions

This section is empty.

Types

type Dispatcher

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

Dispatcher turns published events into push notifications. It implements events.Publisher: install it next to the hub with events.NewMultiPublisher.

func New

func New(o Options) *Dispatcher

New returns a stopped Dispatcher; Start runs it. Events published before Start wait in the queue.

func (*Dispatcher) Close

func (d *Dispatcher) Close()

Close stops the dispatcher, discarding queued events. It is idempotent.

func (*Dispatcher) Dropped

func (d *Dispatcher) Dropped() int64

Dropped is the number of events discarded because the queue was full.

func (*Dispatcher) Handle

func (d *Dispatcher) Handle(ctx context.Context, e events.Event)

Handle processes one event synchronously. The dispatch goroutine calls it for every queued event; tests call it directly.

Only message.created (text and alert messages) and alert.updated notify. A new alert message counts as the alert's "created" transition; alert.updated carries its own transition (protocol.AlertUpdatedEvent).

func (*Dispatcher) Publish

func (d *Dispatcher) Publish(e events.Event)

Publish implements events.Publisher. It never blocks: events that cannot notify anyone are ignored, the rest are queued in publish (= seq) order, and a full queue drops the event and counts it.

func (*Dispatcher) Start

func (d *Dispatcher) Start()

Start launches the dispatch goroutine. It is idempotent.

type Options

type Options struct {
	// DB supplies channel members and their notification preferences.
	DB *store.DB
	// Settings, Presence and Pusher are required.
	Settings Settings
	Presence Presence
	Pusher   Pusher
	// Now is the clock of the mute check; nil means time.Now.
	Now func() time.Time
	// Logger receives drops and failures; it never sees message text.
	Logger *slog.Logger
	// QueueSize defaults to the package QueueSize.
	QueueSize int
}

Options configures New.

type Presence

type Presence interface {
	// Online reports whether the user is online (active) now; it decides
	// whether @here reaches them.
	Online(userID string) bool
	// UserFocusedRecently reports whether the user has a connection whose
	// window is visible now, or had one within the given duration.
	UserFocusedRecently(userID string, within time.Duration) bool
}

Presence is what the dispatcher needs to know about live connections. The realtime hub implements it: connections report window visibility with `focus` frames, and presence follows connection activity.

type Pusher

type Pusher interface {
	// HasSubscriptions reports whether the user has a push subscription.
	HasSubscriptions(ctx context.Context, userID string) bool
	// Send queues a notification for every subscription of the user.
	Send(userID string, n push.Notification)
}

Pusher is the Web Push sender (*push.Service).

type Settings

type Settings interface {
	WebPushEnabled() bool
	PushPayload() string
}

Settings are the instance settings the dispatcher reads (*settings.Store).

Jump to

Keyboard shortcuts

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