BaileysEx.Syncd.ActionMapper (baileys_ex v0.1.0-alpha.9)

Copy Markdown View Source

Maps decoded Syncd mutations to application events.

Examines the SyncActionValue in each decoded mutation and emits the corresponding event (chats update, messages delete, contacts upsert, etc.).

Ports processSyncAction from chat-utils.ts:758-974 and processContactAction/emitSyncActionResults from sync-action-utils.ts.

Summary

Functions

Dispatch sync action results to an event emitter callback.

Process a contact action and return events to emit.

Process a single decoded sync action mutation and return events to emit.

Types

event()

@type event() ::
  {:chats_update, [map()]}
  | {:chats_delete, [String.t()]}
  | {:chats_lock, map()}
  | {:messages_delete, map()}
  | {:messages_update, [map()]}
  | {:contacts_upsert, [map()]}
  | {:creds_update, map()}
  | {:labels_edit, map()}
  | {:labels_association, map()}
  | {:settings_update, map()}
  | {:lid_mapping_update, map()}

sync_action_result()

@type sync_action_result() ::
  {:contacts_upsert, [map()]} | {:lid_mapping_update, map()}

Functions

emit_sync_action_results(emit_fn, results)

@spec emit_sync_action_results((event() -> any()), [sync_action_result()]) :: :ok

Dispatch sync action results to an event emitter callback.

Ports emitSyncActionResults from sync-action-utils.ts:66-74.

process_contact_action(action, id)

@spec process_contact_action(map(), String.t() | nil) :: [sync_action_result()]

Process a contact action and return events to emit.

Always emits contacts_upsert. Optionally emits lid_mapping_update if both LID and PN are available.

Ports processContactAction from sync-action-utils.ts:22-64.

process_sync_action(mutation, me, opts \\ [])

@spec process_sync_action(map(), map(), keyword()) :: [event()]

Process a single decoded sync action mutation and return events to emit.

Returns a list of events (may be empty for unrecognized actions).

Ports processSyncAction from chat-utils.ts:758-974.

Parameters

  • mutation — decoded mutation with :sync_action (SyncActionData) and :index (parsed JSON array)
  • me — current user's contact info %{name: ..., id: ...}
  • opts — optional:
    • :initial_sync — boolean, whether this is initial app state sync
    • :account_settings%{unarchive_chats: boolean()} for initial sync logic