# `ExWapp.Session.Worker.SignalSessions`
[🔗](https://github.com/elchemista/ex_wapp/blob/v0.1.5/lib/ex_wapp/session/worker/signal_sessions.ex#L1)

Keeps the session's Signal sessions loaded, pruned and persisted.

The worker holds Signal sessions in memory and mirrors them to the store; this
module owns that mirroring, plus the two moments the set is pruned: dropping
stale one-way sessions when a connection comes up, and clearing a peer's
sessions when its identity changes.

Every function returns usable state even when the store misbehaves: losing a
Signal session costs one renegotiation, whereas crashing the session process
costs the connection.

# `clear_for_jid`

```elixir
@spec clear_for_jid(ExWapp.Session.Worker.t(), String.t()) ::
  ExWapp.Session.Worker.t()
```

Forgets every session recorded for one peer, across its JID aliases.

# `install_refreshed_identity`

```elixir
@spec install_refreshed_identity(ExWapp.Session.Worker.t(), String.t(), map()) ::
  ExWapp.Session.Worker.t()
```

Replaces a peer's session from a freshly fetched prekey bundle.

Used after an identity change: the old session can no longer decrypt, so it is
rebuilt with `force: true`. An unusable bundle is logged and the state is left
alone rather than raising inside the session process.

# `load`

```elixir
@spec load(ExWapp.Store.t() | nil) :: ExWapp.Signal.SessionStore.t() | nil
```

Loads the persisted sessions, falling back to an empty set.

# `normalize`

```elixir
@spec normalize(term()) :: ExWapp.Signal.SessionStore.t()
```

Coerces a persisted or in-memory session set into the ETS-backed form.

# `persist`

```elixir
@spec persist(ExWapp.Store.t() | nil, ExWapp.Signal.SessionStore.t()) :: :ok
```

Mirrors the in-memory sessions to the store, flushing them to disk.

# `refresh_on_connect`

```elixir
@spec refresh_on_connect(ExWapp.Session.Worker.t()) :: ExWapp.Session.Worker.t()
```

Prunes sessions a new connection should not reuse.

With `signal.reset_sessions_on_connect` every session goes; otherwise only the
one-way ones, which are the sessions a peer never answered on and which would
otherwise make the next send undecryptable.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
