Amarula.Connection.PreKeyOps (amarula v0.3.0)
View SourcePure pre-key decision logic for Amarula.Connection (Baileys
uploadPreKeysToServerIfRequired).
The socket-bound parts — sending the count IQ, the upload round-trip, the
tracked-IQ continuations, finish_login — stay on Connection, since they
drive the login lifecycle. What lives here is pure: building the count-query
node, reading the server's count, choosing the upload target, and deciding
whether an upload is needed. No socket, no state; testable directly.
Summary
Functions
The <iq type=get xmlns=encrypt><count/></iq> that asks how many one-time prekeys the server holds.
True when the last-generated one-time prekey is no longer in local storage.
Read the <count value=…> the server returned (defaults to 0 when absent).
Whether to upload, given the server count and our creds. True when the server
is at/below the target, or our most-recently-generated prekey is gone locally
(Baileys verifyCurrentPreKeyExists).
Upload target for a given server count: the big initial batch when the server holds none, otherwise the min top-up count.
Functions
@spec count_query_node() :: Amarula.Protocol.Binary.Node.t()
The <iq type=get xmlns=encrypt><count/></iq> that asks how many one-time prekeys the server holds.
True when the last-generated one-time prekey is no longer in local storage.
@spec server_count(Amarula.Protocol.Binary.Node.t()) :: non_neg_integer()
Read the <count value=…> the server returned (defaults to 0 when absent).
@spec upload_needed?(non_neg_integer(), pos_integer(), map()) :: boolean()
Whether to upload, given the server count and our creds. True when the server
is at/below the target, or our most-recently-generated prekey is gone locally
(Baileys verifyCurrentPreKeyExists).
@spec upload_target(non_neg_integer()) :: pos_integer()
Upload target for a given server count: the big initial batch when the server holds none, otherwise the min top-up count.