Skip to main content
Version: v6

State Overview

Our UI Components and Compose UI Components rely on reading the state in order to render the UI. Information such as the currently active user, list of muted users, online status, etc. is saved as state inside various state holders (for exampleGlobalState, and others). The state is managed by StatePlugin and adding it to ChatClient is mandatory if you want to use our UI Components/Compose UI Components.

Let's see how we can add the plugin:

// Create a state plugin factory
val statePluginFactory = StreamStatePluginFactory(
config = StatePluginConfig(
// Enables background sync which syncs user actions performed while offline
backgroundSyncEnabled = true,
// Enables tracking online states for users
userPresence = true
),
appContext = context
)

ChatClient.Builder(apiKey, context)
// Add the state plugin to the chat client
.withPlugins(statePluginFactory)
.build()
// Enable background sync which syncs user actions performed while offline
boolean backgroundSyncEnabled = true;
// Enable tracking online states for users
boolean userPresence = true;

// Create a state plugin factory
StreamStatePluginFactory statePluginFactory = new StreamStatePluginFactory(
new StatePluginConfig(
backgroundSyncEnabled,
userPresence
),
context.getApplicationContext()
);

new ChatClient.Builder(apiKey, context)
// Add the state plugin to the chat client
.withPlugins(statePluginFactory)
.build();
note

The StreamStatePluginFactory has been separated from the StreamOfflinePluginFactory and now exists as a distinct, independent plugin factory. This deliberate decision allows for better modularity and independent control over each plugin's functionalities.

Some flags, such as backgroundSyncEnabled and userPresence of the offline plugin's Config have been migrated to StatePluginConfig.

Did you find this page helpful?