Skip to main content

Module state

Module state 

Source
Expand description

Global state management — ChatState, globals, processing gate.

All Tauri-specific globals (TAURI_APP) have been removed. Event emission uses the EventEmitter trait via crate::traits::emit_event.

Structs§

ChatState
PendingInviteAcceptance
SessionGuard
Lightweight handle that remembers the session generation at the moment it was created. Pass it into background tasks (via move-capture into a spawned future) and check is_valid() before any side-effect.
WrapperIdCache

Statics§

ACTIVE_CHAT
Chat id currently visible to the user with auto-mark eligibility — set by the frontend when the chat is open AND pinned to bottom AND the window is active. Used by the inbound event handler to mark new messages read on arrival, so the dock badge never bumps for messages the user is actively watching. Cleared when any of those conditions flips.
BLOSSOM_SERVERS
Blossom media servers with failover. Held in a mutex so the per-account resolver (defaults minus disabled + enabled customs) can refresh it after edits and on login. Until the DB is open, falls back to the seed list.
DISCOVERY_READ_ONLY_RELAYS
Read-only Discovery Relays: queried when SYNCING relay lists but never published to. Ditto acks stranger kind-10050 writes with OK true and then silently drops them, so counting it as a publish landing would falsely advance the list-freshness anchor — but it serves ESTABLISHED accounts’ lists honestly, and those are exactly the users whose existing list a fresh Vector login must find before it dares bootstrap-publish.
DISCOVERY_RELAYS
Discovery Relays: widely-used indexers queried/written for relay-list events (kind 10050) ONLY — never DMs, profiles, or communities. They give list syncs and publishes a rendezvous point that doesn’t depend on the user’s own relay set overlapping anyone else’s. Every entry must be verified to ACCEPT AND SERVE kind 10050 from unknown pubkeys (write + readback); accept-then-silently-drop policy relays reduce coverage invisibly.
ENCRYPTION_ENABLED
ENCRYPTION_KEY
MNEMONIC_SEED
MY_PUBLIC_KEY
MY_SECRET_KEY
NOSTR_CLIENT
NOTIFIED_WELCOMES
PENDING_BUNKER_SETUP
Staged bunker metadata between connect_bunker / start_nostrconnect_session and the subsequent encryption-flow commit. URL is wrapped in Zeroizing because it contains the NIP-46 single-use pairing secret; the pubkey hex is non-secret. setup_encryption / skip_encryption reads this when signer_kind() == Bunker to write the right settings rows via commit_bunker_account_setup.
PENDING_EVENTS
PENDING_INVITE
PENDING_NSEC
PROCESSING_GATE
STATE
TRUSTED_RELAYS
WRAPPER_ID_CACHE

Functions§

active_trusted_relays
bump_session_generation
Advance the session generation. Called at the start of reset_session() so any task that captured the previous value before the swap can detect it and short-circuit before writing to the new account’s state.
clear_my_public_key
Clear MY_PUBLIC_KEY. The Nostr client is taken separately via take_nostr_client() so the caller can shut it down before this clear.
clear_pending_bunker_setup
clear_pending_invite
close_processing_gate
current_session_generation
Snapshot of the current session generation.
discovery_relay_iter
Every discovery relay url (writable + read-only) — the fetch/pool/identity set. Publish copies use DISCOVERY_RELAYS alone.
get_active_chat
get_blossom_servers
has_active_session
Returns true when there is an active session (client + pubkey set).
init_blossom_servers
init_encryption_enabled
is_encryption_enabled_fast
is_processing_allowed
my_public_key
Get the active user’s public key. PublicKey is Copy, so this is by-value.
nostr_client
Get a clone of the active Nostr client. The clone is cheap — Client is internally Arc-counted, so all clones share connections, signers, and subscription state. Returns None when no session is active.
open_processing_gate
pending_bunker_setup
pending_invite
resolve_encryption_enabled
Resolve “is this account encrypted?” from raw DB settings. Single source of truth — every caller (crypto::is_encryption_enabled, init_encryption_enabled, Android bg-sync) delegates here, so the answer is consistent regardless of code path.
resolve_encryption_enabled_from_db
Resolve from the current account’s DB via the global settings helper. Returns false if the DB is not yet open.
set_active_chat
set_encryption_enabled
set_my_public_key
Install the active user’s public key for the current session.
set_nostr_client
Install the Nostr client for the current session. Replaces any prior client without shutting it down — reset_session() is responsible for orderly teardown of the outgoing client.
set_pending_bunker_setup
set_pending_invite
take_nostr_client
Atomically take the current Nostr client out of global state. Used by reset_session() so the post-take shutdown call doesn’t race with new readers.