Skip to main content

Module sync_token

Module sync_token 

Source
Expand description

The Matrix sync-token format GET /sync (P10) emits and GET /keys/changes (P9) also consumes — defined here, once, so every future caller that needs a sync token parses/formats through this module rather than growing a second implementation.

§Format: s{stream_id}_{typing_gen}

stream_id is messenger.db’s own global stream_counter value — the same axis [crate::store::next_stream_id]/ crate::store::max_stream_id and routes::matrix::messaging‘s own "t{stream_id}" /messages pagination token already use. typing_gen is crate::typing::TypingRegistry’s GLOBAL typing generation (see that module’s own doc for why it is global, not per-room) as of the moment this token was minted — routes::matrix::sync compares it against a room’s own current typing serial to tell “this room’s typing set changed since this token” apart from “nothing changed at all” without a busy long-poll loop. The leading s is Matrix’s own conventional sync-token sigil (distinguishing it from /messages’ t-prefixed pagination tokens at a glance in a log line), not a format version — there is exactly one sync token shape, and it is not expected to grow a second one.

§Backward compatibility with the pre-typing-gen form

GET /keys/changes (P9) predates this format’s typing component and only ever emitted/consumed a bare s{stream_id} (or a plain integer). parse still accepts that shorter form, defaulting typing_gen to 0 — never greater than any real room serial a fresh crate::typing::TypingRegistry could have assigned by the time such a token is used, so this default never wrongly suppresses a real typing change (see [crate::typing::TypingRegistry:: current_typing_gen]’s own doc).

Structs§

SyncToken
A parsed sync token: a position in messenger.db’s global stream order, plus the typing generation observed at that position — see the module doc.

Functions§

format
Format a sync token — routes::matrix::sync’s own next_batch is this format’s one emitter.
parse
Parse a sync token back into its (stream_id, typing_gen) pair. Accepts the full s{stream_id}_{typing_gen} form [format] emits, the bare s{stream_id} form (typing_gen defaults to 0 — see the module doc), and a plain integer (a client that echoes a token verbatim never needs this leniency, but it costs nothing and matches routes::matrix::messaging’s own parse_stream_token leniency for the same reason).