Skip to content

SyncAccumulator

Defined in: src/sync-accumulator.ts:265

The purpose of this class is to accumulate /sync responses such that a complete “initial” JSON response can be returned which accurately represents the sum total of the /sync responses accumulated to date. It only handles room data: that is, everything under the “rooms” top-level key.

This class is used when persisting room data so a complete /sync response can be loaded from disk and incremental syncs can be performed on the server, rather than asking the server to do an initial sync on startup.

new SyncAccumulator(opts?): SyncAccumulator

Defined in: src/sync-accumulator.ts:276

IOpts = {}

SyncAccumulator

accumulate(syncResponse, fromDatabase?): void

Defined in: src/sync-accumulator.ts:280

ISyncResponse

boolean = false

void


getJSON(forDatabase?): ISyncData

Defined in: src/sync-accumulator.ts:632

Return everything under the ‘rooms’ key from a /sync response which represents all room data that should be stored. This should be paired with the sync token which represents the most recent /sync response provided to accumulate().

boolean = false

True to generate a sync to be saved to storage

ISyncData

An object with a “nextBatch”, “roomsData” and “accountData” keys. The “nextBatch” key is a string which represents at what point in the /sync stream the accumulator reached. This token should be used when restarting a /sync stream at startup. Failure to do so can lead to missing events. The “roomsData” key is an Object which represents the entire /sync response from the ‘rooms’ key onwards. The “accountData” key is a list of raw events which represent global account data.


getNextBatchToken(): string

Defined in: src/sync-accumulator.ts:781

string


removeEventsFromRoom(roomId, eventIds): void

Defined in: src/sync-accumulator.ts:785

string

string[]

void