Expand description
Event storage — save_event for the flat event architecture.
Structs§
- Reply
Context - Context data for a replied-to message.
Enums§
- Unread
Mark - What
compute_unread_anchordecided a chat’s read marker should become to surface its newest contact message as unread. Computed from the full DB history (RAM may hold only a preview message for an unopened community).
Functions§
- compute_
unread_ anchor - Decide how to mark
chat_identifierunread. Anchors on the newest message strictly before the newest contact message’s second — the count query compares whole seconds with a strict>, so a same-second anchor would leave the target on the boundary and it would read as caught-up. - delete_
event - Delete an event from the events table by ID.
- event_
author - The stored author (npub) of an event, or
Noneif the row (or DB) is absent. Lets the out-of-window moderation-hide path authorize against a paged-out message’s real author. - event_
delete_ context - The owning chat identifier,
mineflag, and stored author (npub) of an event, orNoneif the row (or DB) is absent. Lets delete-affordance resolution give paged-out rows the same verdict as resident ones — residency is a cache detail, not a verdict. - event_
exists - Check if an event exists in the database.
- flush_
message_ batch - Drain a sync loop’s pending message batch into one transaction. The shared flush for the segment-flush pattern: bulk loops COLLECT message saves and call this at delete barriers + loop end (a batched save committing AFTER a delete it originally preceded would resurrect the deleted row — flushing first preserves wire order). Session-guarded HERE so every bulk path gets the same swap-safety: on a stale session the batch is DROPPED, never written into the next account’s DB (the caller’s loop is about to bail anyway).
- get_
all_ chats_ last_ messages - Get the last message for ALL chats in a single batch query. Optimized for app startup (chat list sidebar).
- get_
chat_ message_ count - Get message count for a chat.
- get_
event_ wrap_ context - The stored context a pin proof needs to recover a message’s wrap: its
wrapper_event_idand the rumor’s stored tags (for the epoch binding). - get_
events - Get events for a chat with pagination, optionally filtered by kind. Message/edit content is decrypted via maybe_decrypt.
- get_
message_ views - Get message events with reactions, edits, and attachments composed.
- get_
messages_ around - Anchored (random-access) message window: load
beforemessages up to and including the anchor, plusaftermessages strictly newer than it. O(window) regardless of how deep the anchor sits in the chat — unlike the offset pager, which is O(depth) to reach a far-back message. - get_
pivx_ payments_ for_ chat - Get PIVX payment events for a chat.
- get_
related_ events - Get events that reference specific message IDs (reactions, edits).
- get_
reply_ contexts - Fetch reply context for a list of message IDs.
- get_
system_ events_ for_ chat - Get system events (member joined/left) for a chat.
- is_
own_ event - Whether
event_idis one of our own messages (mine = 1). A reply to our own message is an implicit ping, so notifications treat it like a direct @mention (breaks through a muted channel). Missing row → not ours → false. - message_
exists_ in_ db - Check if a message/event exists in the database. Returns false if DB unavailable.
- populate_
reply_ context - Populate reply context for a single message. Used for real-time messages that don’t go through get_message_views.
- populate_
reply_ contexts - Populate reply context for a PAGE of messages in one query — the sync/back-page
counterpart to
populate_reply_context. Every path that emits a message straight to the UI must resolve the quote first: the frontend renders the emitted payload, and a reply whose parent lies outside the rendered window has no other source for it (a parent inside the window is resolved from memory instead). Messages whose parent isn’t persisted yet are left untouched. - save_
chat_ messages - Batch save messages for a chat — one transaction for the whole slice.
- save_
edit_ event - Save a message edit as a kind=16 event referencing the original message.
- save_
event - save_
message - Save a single message to the database.
- save_
messages_ batch - Save many messages for one chat in a SINGLE transaction — the bulk-sync persist path (community backfill pages, negentropy catch-up). One commit amortizes the per-transaction WAL overhead across the whole page instead of paying it per message.
- save_
messages_ batch_ multi - Multi-chat variant for the DM sync stream: gift-wrapped messages span many contacts, and
splitting per chat would give back most of the batching win. Each message may carry its
gift-wrap ledger entry, committed in the SAME transaction right after its row (see
BatchRow::wrapper). Groups keep their slice order; everything lands in ONE transaction. - save_
pivx_ payment_ event - Save a PIVX payment event, resolving chat_id from conversation identifier.
- save_
reaction_ event - Save a reaction as a kind=7 event referencing the message.
- save_
system_ event_ at - Like
save_system_event_by_idbut stampscreated_atfrom the event’s own authenticated timestamp (clamped to not exceed local now, since the inner author sets it) so a HISTORICALLY-synced presence (join/leave) sorts at the time it happened, not at ingest-time now.received_atstays local now. - save_
system_ event_ by_ id - Save a system event (member joined/left/removed) with dedup. Returns true if inserted, false if duplicate.
- unread_
count_ for_ chat - Unread count for a SINGLE chat, same semantics as
unread_counts. The RAM cache calls this to reconcile one chat (open / delete / retreat) without recomputing every chat’s count. - unread_
counts - Per-chat unread count, computed straight from the DB so it’s correct even when only the last
message is in RAM (the boot state). Mirrors the in-memory walk-back exactly: unread = non-mine
messages newer than the most recent “anchor” (our own message OR the
last_readmarker, whichever is latest). A never-read chat (emptylast_read, no own message) counts all its non-mine messages. Returnschat_identifier → count; chats with 0 unread are omitted. Muted/blocked filtering is left to the caller (it lives in RAM state, cheaply). - update_
wrapper_ event_ id - Update the wrapper event ID for an existing event. Returns true if updated, false if event already had a wrapper_id.
- wrapper_
event_ exists - Check if a wrapper (giftwrap) event ID exists. Returns false if DB unavailable.