Documentation
¶
Index ¶
- type BackfillClient
- type BackfillOptions
- type BackfillReport
- type Blocklist
- type ChannelReport
- type Ingester
- func (ing *Ingester) Backfill(ctx context.Context, client BackfillClient, opts BackfillOptions) (BackfillReport, error)
- func (ing *Ingester) HandlePolled(msg serverapi.ChatMessage)
- func (ing *Ingester) HandlePush(msg serverapi.ChatMessage)
- func (ing *Ingester) SetBlocklist(bl *Blocklist)
- func (ing *Ingester) SetSelfID(id string)
- type Message
- type Query
- type Store
- func (s *Store) ClearCursor(channel string) error
- func (s *Store) Close() error
- func (s *Store) Cursor(channel string) (time.Time, bool, error)
- func (s *Store) Get(id string) (*Message, error)
- func (s *Store) GetByPrefix(prefix string) (*Message, error)
- func (s *Store) Ingest(msg Message) (bool, error)
- func (s *Store) List(q Query) ([]Message, error)
- func (s *Store) MarkChannelRead(channel string) error
- func (s *Store) MarkRead(ids ...string) error
- func (s *Store) MarkSpamBySender(idOrName string) (int, error)
- func (s *Store) Restore(id string) error
- func (s *Store) Search(text string, q Query) ([]Message, error)
- func (s *Store) SearchCount(text string, q Query) (int, error)
- func (s *Store) SetCursor(channel string, oldest time.Time, capped bool) error
- func (s *Store) SoftDelete(id string) error
- func (s *Store) SourceCounts() (map[string]int, error)
- func (s *Store) UnmarkSpamBySender(idOrName string) (int, error)
- func (s *Store) UnreadCounts() (map[string]int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BackfillClient ¶
type BackfillClient interface {
GetChatHistory(ctx context.Context, channel string, payload map[string]any) error
GetRawJSON(key string) []byte
}
BackfillClient is the minimal interface required to perform a channel backfill.
type BackfillOptions ¶
type BackfillOptions struct {
Channels []string
MaxPerChannel int
// ResetCursor clears each channel's saved cursor before crawling so
// the run starts from the most recent page (i.e. "from now") rather
// than resuming from the oldest message previously ingested. Used to
// re-pull current pages after a server-side schema change adds new
// fields that older stored messages are missing.
ResetCursor bool
}
BackfillOptions controls the behaviour of a Backfill run.
type BackfillReport ¶
type BackfillReport struct {
Channels map[string]ChannelReport
}
BackfillReport summarises the results of a Backfill run.
type Blocklist ¶
type Blocklist struct {
// contains filtered or unexported fields
}
Blocklist is a persisted set of spam senders for a single agent. Entries are stored verbatim (preserving display case) but matched case-insensitively against either a message's sender_id or sender display name. It is backed by a JSON array of strings on disk, e.g. data/agents/<agent>/spam_list.json.
func LoadBlocklist ¶
LoadBlocklist reads the blocklist at path. A missing file yields an empty blocklist with no error so first-time callers don't have to special-case it.
func (*Blocklist) Add ¶
Add inserts entry into the blocklist and persists it. It returns (true, nil) if the entry was newly added, or (false, nil) if it was already present (case-insensitive).
func (*Blocklist) IsBlocked ¶
IsBlocked reports whether a message from senderID/sender should be treated as spam. A match on either field (case-insensitive) blocks the message.
type ChannelReport ¶
ChannelReport holds per-channel backfill statistics.
type Ingester ¶
type Ingester struct {
// contains filtered or unexported fields
}
Ingester converts incoming server push events into stored Messages.
func NewIngester ¶
NewIngester creates an Ingester backed by the given Store.
func (*Ingester) Backfill ¶
func (ing *Ingester) Backfill(ctx context.Context, client BackfillClient, opts BackfillOptions) (BackfillReport, error)
Backfill crawls history for each channel in opts.Channels, storing any messages that are not already present in the Store. It stops per channel when it encounters a message ID that already exists, when MaxPerChannel is reached, or when the server returns an empty page.
func (*Ingester) HandlePolled ¶
func (ing *Ingester) HandlePolled(msg serverapi.ChatMessage)
HandlePolled ingests a message discovered via polling get_chat_history.
func (*Ingester) HandlePush ¶
func (ing *Ingester) HandlePush(msg serverapi.ChatMessage)
HandlePush converts a server-pushed ChatMessage and stores it in the mbox. Duplicate messages (same ID) are silently ignored. HandlePush ingests a message received via server push event.
func (*Ingester) SetBlocklist ¶
SetBlocklist attaches a spam blocklist. Incoming messages whose sender_id or sender display name is blocked are stored directly in the spam folder (SpamAt set) regardless of which path ingested them. Pass nil to disable.
type Message ¶
type Message struct {
ID string
Channel string
SenderID string
Sender string
Content string
TargetID string
TargetName string
TimestampUTC time.Time
IngestedAt time.Time
ReadAt *time.Time
DeletedAt *time.Time
// SpamAt is set when the message is in the spam folder — either because it
// was ingested from a blocked sender or flagged via MarkSpamBySender.
// Spam messages are excluded from default queries (List, Search,
// UnreadCounts), like soft-deleted ones.
SpamAt *time.Time
Source string
// EmpireOfficial is true when the server delivered this message through
// the verified empire-leadership pipeline or from an empire NPC. When
// set, SenderID is the empire's own ID. Use it to detect player
// impersonation of empire officials. (server v0.294.0+)
EmpireOfficial bool
}
Message represents a single chat message stored in the mbox.
type Query ¶
type Query struct {
Channel string
SenderID string
UnreadOnly bool
IncludeDeleted bool
// IncludeSpam includes spam-flagged messages in results (they are
// excluded by default). SpamOnly restricts results to spam-flagged
// messages — the "spam folder" view. SpamOnly takes precedence.
IncludeSpam bool
SpamOnly bool
Before time.Time
After time.Time
Limit int
Offset int
}
Query holds filter parameters for retrieving messages. By default, soft-deleted messages are excluded; set IncludeDeleted to see them.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a SQLite-backed message store for a single agent's inbox.
func Open ¶
Open opens (or creates) the SQLite database at dbPath, enables WAL mode, and runs any pending schema migrations.
func (*Store) ClearCursor ¶
ClearCursor removes the backfill cursor for a channel so the next Backfill starts from the most recent page (i.e. "from now") instead of resuming from the oldest previously-seen message.
func (*Store) Cursor ¶
Cursor returns the oldest-seen timestamp for a channel's backfill cursor. Returns (time.Time{}, false, nil) if no cursor exists for the channel.
func (*Store) Get ¶
Get retrieves a single message by ID. Returns nil, nil if not found. Returns soft-deleted messages as well; callers that want to exclude them should check the returned Message.DeletedAt field.
func (*Store) GetByPrefix ¶
GetByPrefix retrieves a single message whose ID starts with prefix. Returns nil, nil if no match. Returns an error if the prefix matches more than one message (caller must disambiguate by using a longer prefix or the full ID).
func (*Store) Ingest ¶
Ingest stores a message in the database. It returns (true, nil) if the message was newly inserted, or (false, nil) if the ID already existed.
func (*Store) List ¶
List returns messages matching the query, ordered newest-first. If q.Limit is 0 it defaults to 20.
func (*Store) MarkChannelRead ¶
MarkChannelRead marks all unread messages in a channel as read.
func (*Store) MarkSpamBySender ¶
MarkSpamBySender flags every non-spam message whose sender_id or sender display name matches idOrName (case-insensitive) as spam, moving it into the spam folder. It returns the number of messages newly flagged.
func (*Store) Restore ¶
Restore clears the soft-delete flag on a message, making it visible to default queries again. No-op if not deleted.
func (*Store) Search ¶
Search performs a full-text search over messages, with optional Query filters. Default limit is 20 if q.Limit is 0.
func (*Store) SearchCount ¶
SearchCount returns the total number of messages matching the FTS query, applying the same filters (Channel, SenderID, UnreadOnly, IncludeDeleted) as Search but ignoring Limit/Offset.
func (*Store) SoftDelete ¶
SoftDelete marks a message as deleted. It is hidden from default queries (List, Search) but remains in the store and can be undone with Restore. No-op if the message is already deleted.
func (*Store) SourceCounts ¶
SourceCounts returns a map of source → message count.
func (*Store) UnmarkSpamBySender ¶
UnmarkSpamBySender clears the spam flag on every spam message whose sender_id or sender display name matches idOrName (case-insensitive), restoring it to its original folder. It returns the number of messages restored.