Skip to content

CHATHISTORY Reference ​

The draft/chathistory extension, as ferrixd implements it. Conceptual overview and sizing: Message History guide.

Request grammar ​

CHATHISTORY <subcommand> <target> <selector…> <limit>
  • target — a channel (membership required) or a nick (DM history — the target pair is symmetric, both participants see the same timeline).
  • selector — *, timestamp=<ISO8601 with ms, UTC>, or msgid=<id> (MSGREFTYPES=timestamp,msgid).
  • limit — messages to return; clamped to 1…100 (CHATHISTORY=100 in ISUPPORT); defaults to 50 when absent or unparseable.

Subcommands ​

SubcommandFormReturns
LATESTLATEST <target> * <limit>the most recent messages
LATESTLATEST <target> <sel> <limit>messages newer than the selector
BEFOREBEFORE <target> <sel> <limit>messages older than the selector
AFTERAFTER <target> <sel> <limit>messages newer than the selector
AROUNDAROUND <target> <sel> <limit>messages surrounding the selector
BETWEENBETWEEN <target> <sel1> <sel2> <limit>messages between two selectors (either order)
TARGETSTARGETS <ts1> <ts2> <limit>which targets (channels/DM partners) have activity in the window

Examples:

CHATHISTORY LATEST #forge * 50
CHATHISTORY BEFORE #forge timestamp=2026-07-13T20:00:00.000Z 100
CHATHISTORY AFTER  alice msgid=00000000000004cf 50
CHATHISTORY BETWEEN #forge msgid=00000000000004cf timestamp=2026-07-13T21:00:00.000Z 100
CHATHISTORY TARGETS timestamp=2026-07-13T00:00:00.000Z timestamp=2026-07-13T23:59:59.000Z 20

Response format ​

With the batch capability, results arrive wrapped:

« :irc.example.org BATCH +ref chathistory #forge
« @batch=ref;msgid=…;time=… :bob!bob@host PRIVMSG #forge :…
« @batch=ref;msgid=…;time=… :eve!eve@host NOTICE #forge :…
« :irc.example.org BATCH -ref

Replayed messages carry the same msgid they had live, and their original time=. account= tags are replayed for clients with account-tag. Without batch, messages are sent unwrapped.

Clients that negotiated draft/event-playback additionally receive the stored channel events (JOIN, PART, QUIT, NICK, KICK, TOPIC, MODE) and kept TAGMSGs in their original position; everyone else gets only PRIVMSG and NOTICE. A TOPIC set on this server is replayed with the same msgid it had live; a topic change that arrived from a linked server was delivered live without a msgid, so its replayed msgid has no live counterpart.

Errors (standard-replies) ​

ReplyWhen
FAIL CHATHISTORY NEED_MORE_PARAMSmissing subcommand/target/selector
FAIL CHATHISTORY INVALID_TARGETchannel you're not a member of, or unknown target
FAIL CHATHISTORY INVALID_PARAMSmalformed selector, unknown subcommand

Storage semantics ​

  • msgid — a server-assigned, strictly monotonic 16-hex-digit ID. Ordering by msgid equals ordering by arrival. With persistence enabled, the counter continues across restarts (no reuse, no regression).
  • Ring buffers — per-target retention is history_len (default 500); the number of distinct targets is bounded by history_max_targets (default 50,000) with least-recently-active eviction.
  • What's recorded — PRIVMSG and NOTICE to channels and users (including multiline batch parts); channel events (JOIN, PART, QUIT, NICK, KICK, TOPIC, MODE) for draft/event-playback; and TAGMSGs meant to last — those carrying +draft/persist or a +draft/react reaction. Other TAGMSGs (typing notifications, call signalling) are never recorded, and neither are plugin-vetoed messages. Kept TAGMSGs are recorded only on the sender's server; those relayed from a linked server are delivered but not stored.
  • Redaction — REDACT removes a message from memory and from the database (and so from the search index).
  • DM identity — a direct conversation is filed under its participants' identities: a logged-in user's account, a guest's nick. Logging in to an account named like a former guest does not reveal that guest's conversations.

SQLite schema ​

With [persistence] enabled, history rows are written behind (batches of up to 256 per transaction, WAL journal) to:

sql
CREATE TABLE history (
   id      INTEGER PRIMARY KEY AUTOINCREMENT,
   folded  TEXT    NOT NULL,   -- case-folded target (channel or DM pair key)
   msgid   TEXT    NOT NULL,
   time_ms INTEGER NOT NULL,   -- unix milliseconds, UTC
   source  TEXT    NOT NULL,   -- nick!user@host at send time
   account TEXT,               -- sender's account, if logged in
   kind    INTEGER NOT NULL,   -- see below
   target  TEXT    NOT NULL,   -- display form of the target
   body    TEXT    NOT NULL    -- text, event detail, or a TAGMSG's client tags
);
CREATE INDEX idx_history_folded ON history(folded, id);
CREATE INDEX idx_history_time   ON history(time_ms);

-- With search enabled: an external-content FTS5 index over `body`,
-- kept in sync by insert/update/delete triggers.
CREATE VIRTUAL TABLE history_fts USING fts5(
   body, content='history', content_rowid='id',
   tokenize='unicode61 remove_diacritics 2'
);

kind values: 0 PRIVMSG, 1 NOTICE, 2 JOIN, 3 PART, 4 QUIT, 5 NICK (body = new nick), 6 TOPIC (body = new topic), 7 KICK (body = <victim> <reason>), 8 MODE (body = <flags> [args…]), 9 TAGMSG (body = its client-only tags in wire form). Readers should treat unknown values as messages, as ferrixd does.

On startup the most recent load_limit rows (default 5000) are loaded into RAM and the msgid counter reseeds past the highest loaded ID. The table is pruned at startup to the most recent 100,000 rows. The file is a normal SQLite database — safe to query read-only for archival or analytics (the same file also holds channel registrations, self-registered accounts, the channels always-on users rejoin, and the E2EE key directory).

Dual-licensed under MIT or Apache-2.0.