Class SyncAccumulator

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.

Hierarchy

  • SyncAccumulator

Constructors

Properties

accountData: Record<string, IMinimalEvent> = {}
inviteRooms: Record<string, IInvitedRoom> = {}
joinRooms: {
    [roomId: string]: IRoom;
} = {}

Type declaration

nextBatch: null | string = null
opts: IOpts = {}

Methods

  • Accumulate incremental /sync room data.

    Parameters

    • syncResponse: ISyncResponse

      the complete /sync JSON

    • fromDatabase: boolean = false

      True if the sync response is one saved to the database

    Returns void

  • 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().

    Parameters

    • forDatabase: boolean = false

      True to generate a sync to be saved to storage

    Returns 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.

Generated using TypeDoc