ExWapp.Session.JIDUtils (ExWapp v0.1.2)

Copy Markdown View Source

Pure JID helpers used by session send/decrypt flows.

Keeping these helpers isolated makes the session orchestration code easier to reason about and test.

Summary

Functions

build_dm_target_specs(recipient_targets, own_targets)

@spec build_dm_target_specs([String.t()], [String.t()]) :: [
  %{jid: String.t(), payload_kind: :recipient | :own}
]

build_self_chat_fallback_target_specs(recipient_targets, own_targets, destination_jid)

@spec build_self_chat_fallback_target_specs([String.t()], [String.t()], String.t()) ::
  [
    %{jid: String.t(), payload_kind: :recipient | :own}
  ]

Fallback self-chat strategy used when a DSM-only send appears silently dropped.

It keeps one primary target as :recipient payload and uses :own payload for the remaining fanout targets.

build_self_chat_target_specs(recipient_targets, own_targets, destination_jid)

@spec build_self_chat_target_specs([String.t()], [String.t()], String.t()) :: [
  %{jid: String.t(), payload_kind: :recipient | :own}
]

Builds target specs for self-chat fanout.

WhatsMeow parity: for self-chat, every non-current target gets the DSM payload. There is no plain "recipient payload" branch in self-chat fanout.

current_device_target?(jid, own_device_id)

@spec current_device_target?(term(), integer()) :: boolean()

device_id(jid)

@spec device_id(term()) :: non_neg_integer() | nil

has_explicit_device?(jid)

@spec has_explicit_device?(term()) :: boolean()

identity(jid)

@spec identity(term()) :: {String.t(), String.t()}

lid_jid?(jid)

@spec lid_jid?(term()) :: boolean()

map_to_preferred_family(target_jid, preferred_base_jid, lid_mapping)

@spec map_to_preferred_family(term(), term(), map() | nil) :: String.t()

normalize_for_signal(jid)

@spec normalize_for_signal(term()) :: String.t()

normalize_target_list(targets)

@spec normalize_target_list(term()) :: [String.t()]

normalize_with_device(jid)

@spec normalize_with_device(term()) :: String.t()

resolve_signal_encryption_jid(target_jid, lid_mapping)

@spec resolve_signal_encryption_jid(term(), map() | nil) :: String.t()

strip_device(jid)

@spec strip_device(term()) :: String.t()

user_part(jid)

@spec user_part(term()) :: String.t()