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.
- 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_
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.
- save_
chat_ messages - Batch save messages for a chat.
- save_
edit_ event - Save a message edit as a kind=16 event referencing the original message.
- save_
event - Save a StoredEvent to the events table.
- save_
message - Save a single message to the database.
- 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_
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.