ExWapp.AppState.Engine.Sync (ExWapp v0.1.2)

Copy Markdown View Source

Synchronization and transport helpers for app-state collections.

This module owns the IQ request/response flow with WhatsApp, including collection fetches, mutation sends, external blob downloads, and the sequencing required to apply snapshots and patch chains into the local store.

Summary

Functions

Applies a collection response payload to the local store.

Applies a collection response payload and optionally uses a live session when external blobs must be fetched while decoding snapshots or patch chains.

Applies a collection response using feature-specific persistence options.

Fetches a single app-state collection and applies its snapshot and patches.

Synchronizes the affected collection, encodes and sends a mutation patch, then applies the acknowledged change locally and schedules a background refresh. Operations for the same store collection are serialized.

Types

hash_state()

@type hash_state() :: %{version: non_neg_integer(), hash: binary()}

patch_info()

@type patch_info() :: ExWapp.AppState.Engine.Codec.patch_info()

Functions

apply_collection_response(store, collection_name, response)

@spec apply_collection_response(struct(), String.t(), ExWapp.Binary.Node.t()) ::
  {:ok, non_neg_integer()} | {:error, term()}

Applies a collection response payload to the local store.

apply_collection_response(store, collection_name, response, session)

@spec apply_collection_response(
  struct(),
  String.t(),
  ExWapp.Binary.Node.t(),
  pid() | nil
) ::
  {:ok, non_neg_integer()} | {:error, term()}

Applies a collection response payload and optionally uses a live session when external blobs must be fetched while decoding snapshots or patch chains.

apply_collection_response(store, collection_name, response, session, opts)

@spec apply_collection_response(
  struct(),
  String.t(),
  ExWapp.Binary.Node.t(),
  pid() | nil,
  keyword()
) ::
  {:ok, non_neg_integer()} | {:error, term()}

Applies a collection response using feature-specific persistence options.

The :max_records option is forwarded to call-log mutations.

fetch_collection(session, store, collection_name)

@spec fetch_collection(GenServer.server(), struct(), String.t()) ::
  :ok | {:error, term()}

Fetches a single app-state collection and applies its snapshot and patches.

fetch_collection(session, store, collection_name, opts)

@spec fetch_collection(GenServer.server(), struct(), String.t(), keyword()) ::
  :ok | {:error, term()}

send_mutation(session, patch_info, store)

@spec send_mutation(GenServer.server(), patch_info(), struct()) ::
  {:ok, hash_state(), map()} | {:error, term()}

Synchronizes the affected collection, encodes and sends a mutation patch, then applies the acknowledged change locally and schedules a background refresh. Operations for the same store collection are serialized.

send_mutation(session, patch_info, store, opts)

@spec send_mutation(GenServer.server(), patch_info(), struct(), keyword()) ::
  {:ok, hash_state(), map()} | {:error, term()}