Amarula.Connection.AppStateOps (amarula v0.2.2)

View Source

Pure app-state-sync helpers for Amarula.Connection.

The sync flow is Storage- and IQ-bound — requesting patches, persisting collection state, decoding against stored keys, emitting events — and stays on Connection. What's pure lives here: pulling shared sync-keys out of incoming messages, and partitioning decoded changes into the chat/contact event lists.

Summary

Functions

Partition decoded app-state changes into {chats, contacts} for the :chats_update / :contacts_update events.

Extract any appStateSyncKeyShare keys carried in a message as [{key_id_b64, key_data}]. Returns [] for messages without a share.

All appStateSyncKeyShare keys across a batch of messages, flattened.

Functions

partition_changes(changes)

@spec partition_changes([{:chat | :contact, term()}]) :: {[term()], [term()]}

Partition decoded app-state changes into {chats, contacts} for the :chats_update / :contacts_update events.

sync_keys(arg1)

@spec sync_keys(map()) :: [{String.t(), binary()}]

Extract any appStateSyncKeyShare keys carried in a message as [{key_id_b64, key_data}]. Returns [] for messages without a share.

sync_keys_in(messages)

@spec sync_keys_in(Enumerable.t()) :: [{String.t(), binary()}]

All appStateSyncKeyShare keys across a batch of messages, flattened.