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
Nonewhen 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.Nonewhen 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_looponce. 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_removedwith reason “self-destruct” per purged row so the UI can derez it.