Skip to content

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.

Browser
await client.conversation.sync();

Manually request sync from other devices

When a device installation comes online, it automatically sends a request to other devices on the network to sync conversations and messages. However, in scenarios where this automatic process is interrupted, you can manually trigger a sync request.

Browser
await client.sendSyncRequest();

Sync new conversations

Get any new group chat or DM conversations from the network.

Browser
await client.conversations.sync();

Sync new welcomes, conversations with unread messages, and preferences

Use syncAll to sync the following from the network:

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.

Browser
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:

Kotlin
// Drop the local database connection
client.dropLocalDatabaseConnection()

Reconnect to the database

Reconnect to the local database after dropping the connection:

Kotlin
// Reconnect to the local database
client.reconnectLocalDatabase()