Skip to main content

Module events

Module events 

Source
Expand description

Event storage — save_event for the flat event architecture.

Structs§

ReplyContext
Context data for a replied-to message.

Enums§

UnreadMark
What compute_unread_anchor decided 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_identifier unread. 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 None if 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, mine flag, and stored author (npub) of an event, or None if 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 before messages up to and including the anchor, plus after messages 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_id is 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_id but stamps created_at from 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_at stays 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_read marker, whichever is latest). A never-read chat (empty last_read, no own message) counts all its non-mine messages. Returns chat_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.