Sync conversations and messages
🎥 walkthrough: Syncing
This video provides a walkthrough of key concepts required to implement syncing correctly.
Sync a specific conversation
Get all new messages and group updates (name, description, etc.) for a specific conversation from the network.
await client.conversation.sync();Send a sync request
Send a request to other devices on the network to sync conversations and messages to the current installation. Call this after creating a client on a new installation to pull in historical data from existing installations.
To learn more, see History sync.
await client.sendSyncRequest();Sync new conversations
Get any new group chat or DM conversations from the network.
await client.conversations.sync();Sync new welcomes, conversations with unread messages, and preferences
Use syncAll to sync the following from the network:
- New welcomes
- Group chat and DM conversations with a consent state of allowed or unknown that have unread messages
- Preference updates
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.
To sync conversations regardless of consent state, pass [ALLOWED, UNKNOWN, DENIED].
To sync preferences only, you can call preferences.sync. Note that preferences.sync will also sync welcomes to ensure that you have all potential new installations before syncing.
The method returns a summary object that includes the total number of conversations eligible for syncing and the number of conversations that were actually synced.
await client.conversations.syncAll(['allowed']);Manage database connections
In some scenarios, you may need to temporarily release the local database connection, such as when performing database maintenance or when the app goes into the background for an extended period.
Drop the database connection
Temporarily release the connection to the local database:
// Drop the local database connection
await client.dropLocalDatabaseConnection();Reconnect to the database
Reconnect to the local database after dropping the connection:
// Reconnect to the local database
await client.reconnectLocalDatabase();
