Skip to content

Sync

Syncing pulls new envelopes into the local database. Every read API reads the local database, so a sync makes new data visible to list, messages, and countMessages.

CallPulls
conversation.sync()Messages and group updates for one conversation
conversations.sync()Conversations you have been added to
conversations.syncAll(consentStates)Welcomes, changed conversations, and preferences
preferences.sync()Welcomes, consent records, and HMAC keys

Kotlin and Swift name syncAll as syncAllConversations.

const
const summary: void
summary
= await
client: Client<BuiltInContentTypes>
client
.
Client<BuiltInContentTypes>.conversations: Conversations<BuiltInContentTypes>

Gets the conversations manager for this client

conversations
.
Conversations<BuiltInContentTypes>.syncAll(consentStates?: ConsentState[]): Promise<void>

Synchronizes all conversations and messages from the network with optional consent state filtering

@paramconsentStates - Optional array of consent states to filter by

@returnsPromise that resolves when sync is complete

syncAll
(
consentStates: ConsentState[]
consentStates
);

syncAll first processes welcomes. It then compares each local conversation cursor with the newest backend envelope and skips conversations with no new data. A membership change counts as new data. A conversation with no cursor is always included.

Summary fieldMeaning
numEligibleConversations that match the consent filter
numSyncedEligible conversations that were behind and active

An inactive conversation is eligible but is not synced. Therefore, numSynced can be less than numEligible without a failure.

We recommend syncing messages for allowed conversations only. This ensures that spammy conversations with a consent state of unknown don’t take up networking resources. This also ensures that unwanted spam messages aren’t stored in the user’s local database.

Device sync keeps a user’s installations agreed on consent records and HMAC root keys. Messages do not move between installations. Use an archive to move message history.

An update from one installation is applied by the others when they next call preferences.sync() or syncAll().

Device sync is on by default. Set disableDeviceSync: true on Browser and Node, or deviceSyncEnabled: false on Kotlin and Swift, to turn it off.