tracker

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 7 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 tracker turns changes in chat.db into events.

New messages are found by ROWID high-water mark, so none are missed even if a file notification is. Changes to existing messages (sent, delivered, read, edited, unsent, failed, played) are found by diffing a cheap state snapshot of recent messages against the previous one. Chat read markers are diffed the same way.

Index

Constants

View Source
const (
	ChangeSent      = "sent"
	ChangeDelivered = "delivered"
	ChangeRead      = "read"
	ChangePlayed    = "played"
	ChangeEdited    = "edited"
	ChangeUnsent    = "unsent"
	ChangeFailed    = "failed"
)

Change names reported in message.updated events.

Variables

This section is empty.

Functions

func Diff

func Diff(prev, cur db.MessageState) []string

Diff lists what changed between two states of the same message.

Types

type ChatReadEvent

type ChatReadEvent struct {
	ChatID string    `json:"chat_id"`
	ReadAt time.Time `json:"read_at"`
}

ChatReadEvent is the data of chat.read events.

type MessageEvent

type MessageEvent struct {
	Message present.Message `json:"message"`
}

MessageEvent is the data of message.received/sent events.

type Options

type Options struct {
	DB        *db.DB
	Bus       *events.Bus
	Presenter *present.Presenter
	// Window is how far back changes to existing messages are tracked.
	// Default 7 days.
	Window time.Duration
	// BackfillAge suppresses events for new rows dated more than this far in
	// the past (e.g. history downloaded from iCloud). Default 1 hour.
	BackfillAge time.Duration
	// OnNewMessage, if set, is called for every new row (including
	// suppressed backfill) before events are published.
	OnNewMessage func(*db.Message)
	// OnMessageUpdated, if set, is called with each changed message.
	OnMessageUpdated func(m *db.Message, changes []string)
	Now              func() time.Time
}

type Tracker

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

func New

func New(o Options) *Tracker

func (*Tracker) Init

func (t *Tracker) Init(ctx context.Context) error

Init records the current state without emitting events.

func (*Tracker) MaxRowID

func (t *Tracker) MaxRowID() int64

MaxRowID is the highest message ROWID processed.

func (*Tracker) Run

func (t *Tracker) Run(ctx context.Context, ticks <-chan struct{})

Run processes ticks until ctx is done. Errors are logged and the work is retried on the next tick.

func (*Tracker) Tick

func (t *Tracker) Tick(ctx context.Context) error

Tick checks for new messages, message updates and chat read changes.

type UpdateEvent

type UpdateEvent struct {
	Message present.Message `json:"message"`
	Changes []string        `json:"changes"`
}

UpdateEvent is the data of message.updated events.

Jump to

Keyboard shortcuts

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