Skip to main content

Module self_destruct

Module self_destruct 

Source
Expand description

Self-Destruct Timer — per-chat NIP-40 message expiry (“disappearing messages”). The per-chat lifespan is a DURATION stored in the account settings KV; each outgoing DM in that chat is stamped with an absolute NIP-40 expiry so relays drop the gift-wrap and every compliant client purges its local copy on schedule. Purge is local-only per client — the expiry tag travels with the message, so no delete broadcast is needed.

Functions§

chat_duration_secs
Configured self-destruct DURATION in seconds for a chat, or None when the chat keeps messages permanently. Stored per-account, so it naturally follows the active account’s DB pool.
resolve_send_expiry
Resolve the absolute NIP-40 expiry (unix seconds) to stamp on a NEW message sent to chat_id, honoring the chat’s configured lifespan. None when the chat is permanent.
run_sweeper_loop
The self-destruct sweep loop: purge, then sleep until the next expiry is due (adaptive — 1s-tight near a deadline, up to SWEEP_MAX_SECS when idle). The immediate first pass catches anything that expired while offline. Hosts with their own async runtime (e.g. Tauri) should spawn this directly.
set_chat_duration_secs
Set the self-destruct duration for a chat. None (or 0) clears it back to permanent by removing the key.
start_sweeper
Convenience for tokio-native hosts (CLI/SDK): spawn run_sweeper_loop once. Idempotent — a second call is a no-op.
sweep_expired
Purge every message whose NIP-40 expiry has passed: drop it from STATE and the DB, remove cached attachment files no sibling still needs, and — for OUR OWN file messages — issue a Blossom blob delete (blobs carry no self-expiry). Emits message_removed with reason “self-destruct” per purged row so the UI can derez it.