App state sync (Syncd) — runtime orchestration for cross-device state synchronization.
Provides patch construction, outbound push (app_patch/3), full resync
(resync_app_state/4), and the high-level chat_modify/4 entry point.
Delegates encoding/decoding to Syncd.Codec and action mapping to
Syncd.ActionMapper.
Ports appPatch, resyncAppState, chatModify from Baileys chats.ts:465-902.
Summary
Functions
Send an outbound app state patch to the server.
Construct the app-state patch structure without sending it.
High-level chat modification — builds a patch and sends it.
Build a Baileys-style app-state patch for the given action and pass it to the provided transport callback when one is supplied.
Full resync of app state collections from the server.
Types
@type operation() :: :set | :remove
@type patch() :: %{ sync_action: map(), index: [String.t()], type: patch_type(), api_version: pos_integer(), operation: operation() }
@type patch_type() ::
:critical_block
| :critical_unblock_low
| :regular_high
| :regular_low
| :regular
Functions
@spec app_patch( term(), GenServer.server() | BaileysEx.Connection.Store.Ref.t(), patch(), keyword() ) :: :ok | {:error, term()}
Send an outbound app state patch to the server.
Acquires the current sync version, encodes the patch, sends it via IQ, and persists the updated state.
Ports appPatch from chats.ts:779-853.
Parameters
queryable— function or{module, pid}for sending IQ queriesstore— Store server or Refpatch_create—%{type:, index:, sync_action:, api_version:, operation:}opts— options::emit_own_events— boolean (defaulttrue):event_emitter— pid:me— current user contact info
Construct the app-state patch structure without sending it.
@spec chat_modify( term(), GenServer.server() | BaileysEx.Connection.Store.Ref.t(), atom(), String.t(), term(), keyword() ) :: :ok | {:error, term()}
High-level chat modification — builds a patch and sends it.
Ports chatModify from chats.ts:899-902.
@spec push_patch(term(), atom(), String.t(), term(), keyword()) :: {:ok, patch()} | {:error, term()}
Build a Baileys-style app-state patch for the given action and pass it to the provided transport callback when one is supplied.
@spec resync_app_state(term(), GenServer.server(), [patch_type()], keyword()) :: :ok | {:error, term()}
Full resync of app state collections from the server.
Fetches snapshots and patches for each collection, decodes them, persists the updated LTHash state, and emits sync action events.
Ports resyncAppState from chats.ts:479-632.
Parameters
queryable— function or{module, pid}for sending IQ queriesstore— Store server or Ref for key/version persistencecollections— list of collection names to syncopts— options::is_initial_sync— boolean (defaultfalse):event_emitter— pid to receive events:me— current user contact info:validate_snapshot_macs— boolean (defaultfalse):validate_patch_macs— boolean (defaultfalse)