Skip to main content

Module inbound

Module inbound 

Source
Expand description

v2 inbound bridge — turns opened v2 events into the protocol-agnostic InboundEventHandler callbacks the rest of Vector (and the SDK’s on_message) already consumes. The handler is the seam: v1 and v2 both feed it, so a bot receives v2 messages with no SDK change.

Dispatch is by which plane a kind-1059 wrap opens under. A received wrap is tried against each held channel’s Chat-Plane key (author match, no trial decrypt), then the Guestbook plane; a control-plane fold is a heavier separate path (metadata/roster), handled by the service refresh, not here.

Enums§

ChatPersist
What applying a v2 chat event to STATE yielded — the caller persists it (async) once the STATE lock is dropped. Mirrors v1’s IncomingEvent for the chat sub-kinds: a message row is saved fresh or re-saved (a landed reaction rides the row), a delete drops it. Persistence is the caller’s so the apply step stays sync + lock-scoped.
DispatchedV2
The typed outcome of dispatching one v2 wrap.

Functions§

apply_chat_to_state
Apply an opened v2 ChatEvent to STATE (dedup + aggregate onto the SHARED ChatState), mirroring v1’s ingest_message/apply_reaction/apply_delete. Sync: the DB dedup read + STATE mutation run under the caller’s lock; the caller then does the async DB persist on the returned ChatPersist (see persist_chat). Returns None for a duplicate, a non-persisted kind (typing/webxdc), an edit (increment 2), or an aggregate whose target isn’t resident in this channel.
chat_message_to_message
Build a protocol-agnostic Message from an opened v2 chat Message event. Mirrors v1’s build_message field-for-field (id = the rumor id, ms time, mine, npub, imeta attachments, NIP-30 emoji, the reply reference), so the frontend/SDK renderers treat a v2 message identically to a v1 or DM one.
dispatch_wrap
Dispatch a received kind-1059 wrap for community: route it to the plane it opens under. Chat events are returned OPENED (the realtime layer persists, then fires callbacks from the outcome); only the non-persisted kinds (typing, guestbook presence) fire their callback inline here. Purely in-memory — so this stays offline-testable.
persist_chat
Persist an apply_chat_to_state outcome to the shared events DB — async, run by the caller AFTER the STATE lock drops (a message row carries its reactions, so a reaction re-saves the row; a delete drops it).
persist_chat_event
Apply an already-opened chat event to STATE + the shared store — the LIVE counterpart of crate::VectorCore::v2_backfill_channel’s catch-up persistence. The dispatcher opened the wrap (so nothing decrypts twice); the returned outcome is what the caller’s callbacks fire from — a duplicate, a non-resident target, or a forged edit/delete yields None and nothing re-fires.