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§
- Chat
Persist - What applying a v2 chat event to STATE yielded — the caller persists it (async)
once the STATE lock is dropped. Mirrors v1’s
IncomingEventfor 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. - Dispatched
V2 - The typed outcome of dispatching one v2 wrap.
Functions§
- apply_
chat_ to_ state - Apply an opened v2
ChatEventto STATE (dedup + aggregate onto the SHAREDChatState), mirroring v1’singest_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 returnedChatPersist(seepersist_chat). ReturnsNonefor 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
Messagefrom an opened v2 chat Message event. Mirrors v1’sbuild_messagefield-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_stateoutcome 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 yieldsNoneand nothing re-fires.