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
ChatStateHandle
The account’s chats and profiles in memory.
NotifiedWelcomesHandle
npubs already welcomed, so the greeting fires once per contact — per account, since the contact list is.
PendingEventsHandle
Events parked while the processing gate is closed (encryption migration). Per-account: they are this account’s inbound traffic, awaiting its key.
PendingInviteAcceptance
WrapperIdCache
WrapperIdCacheHandle
Which wrapper events this account has already ingested.

Statics§

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_SECRET_KEY
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_NIP55_SETUP
Staged NIP-55 pairing result between login_with_nip55 and the subsequent encryption-flow commit. Both fields are public material (identity pubkey + signer package name), so no Zeroizing — unlike bunker, a NIP-55 account stages nothing secret. setup_encryption / skip_encryption reads this when signer_kind() == Nip55 to write the right settings rows via commit_nip55_account_setup.
PENDING_NSEC
PROCESSING_GATE
STATE
TRUSTED_RELAYS
WRAPPER_ID_CACHE

Functions§

active_trusted_relays
clear_message_tombstones
Drop the delete-tombstone set on an account switch.
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
clear_pending_nip55_setup
close_processing_gate
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.
note_message_deleted
Record that message_id was deleted this session (called where the deletion is decided).
open_processing_gate
pending_bunker_setup
pending_invite
pending_nip55_setup
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.
seed_message_tombstones
Seed the tombstone set from the account’s durable deleted_messages rows, making was_message_deleted survive restarts and account swaps. Called at account DB init (the set was cleared by the session bump on swap).
set_active_chat
set_blossom_servers
Install this account’s resolved server list.
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_nostr_client_if_absent
Install client only if this session has none yet, reporting whether it took. Logins race on Android, where a service-only background sync can install a client before the Activity’s login reaches this point; the loser must drop its own rather than replace a live one.
set_pending_bunker_setup
set_pending_invite
set_pending_nip55_setup
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.
was_message_deleted
Whether message_id was deleted this session.