Skip to main content

BatchingPersist

Struct BatchingPersist 

Source
pub struct BatchingPersist<'a> { /* private fields */ }
Expand description

Wraps any handler for a bulk-sync drain loop: every callback delegates to the inner handler, but committed messages BUFFER here instead of saving one transaction each — the loop calls BatchingPersist::flush periodically and at stream end to land them in batched transactions (save_messages_batch_multi).

Deferral is recoverable because the wrapper ledger (the negentropy fingerprint set) rides the flush transaction: a message lost to a crash, a stale-session drop, or a failed flush leaves its wrapper unledgered, so the next reconciliation re-delivers it.

Implementations§

Source§

impl<'a> BatchingPersist<'a>

Source

pub fn new(inner: &'a dyn InboundEventHandler) -> Self

Source

pub fn buffered(&self) -> usize

How many messages are waiting — the loop’s flush-threshold probe.

Source

pub async fn flush(&self, session: &SessionGuard) -> usize

Drain the buffer into batched transactions (grouped by chat, arrival order kept). On a stale session the drained messages are DROPPED, never written into the next account’s DB — their wrappers stay unledgered, so negentropy re-delivers them when the original account returns.

Source

pub async fn try_flush(&self, session: &SessionGuard) -> Result<usize, String>

Self::flush, but a persist failure is distinguishable from “nothing to write” — callers that gate follow-on effects on the ledger actually holding the batch (reconcile-cursor births) need the difference: an advance over an unledgered batch skips those events forever.

Trait Implementations§

Source§

impl InboundEventHandler for BatchingPersist<'_>

Source§

fn buffer_persist( &self, chat_id: &str, msg: &Message, wrapper: Option<([u8; 32], u64)>, ) -> bool

Bulk-sync persist intercept: return true to take ownership of persisting a committed DM/file message — the commit then SKIPS its per-message save AND its wrapper-ledger write (wrapper = the gift-wrap’s (id_bytes, created_at); the owner MUST commit it in the same transaction as the message row, or the message loses crash/drop recoverability). Streaming sync loops (see BatchingPersist) buffer here and drain many messages into one transaction. Default false keeps the per-message save.
Source§

fn on_dm_received(&self, chat_id: &str, msg: &Message, is_new: bool)

A DM text message was received and committed to STATE + DB.
Source§

fn on_file_received(&self, chat_id: &str, msg: &Message, is_new: bool)

A DM file attachment was received and committed to STATE + DB.
Source§

fn on_reaction_received(&self, chat_id: &str, msg: &Message)

A reaction was received and applied to a message.
Source§

fn on_message_deleted(&self, chat_id: &str, message_id: &str)

A previously-stored message was deleted by its sender (Layer 2 cooperative hide via NIP-09 over NIP-17). Frontend drops the row.
Source§

fn on_community_invite(&self, community_id: &str)

A Community invite was received over a gift wrap and the local user was joined (member-view Community persisted). Platform refreshes the Community subscription so messages start flowing, and surfaces the new Community in the UI.
Source§

fn on_community_message(&self, chat_id: &str, msg: &Message, is_new: bool)

A new Community channel message was received, ingested into STATE, and persisted.
Source§

fn on_community_update(&self, chat_id: &str, target_id: &str, msg: &Message)

A reaction or edit was applied to an existing Community message. target_id is the affected message; msg is the live-updated view.
Source§

fn on_community_removed(&self, chat_id: &str, target_id: &str)

A Community message was removed (cooperative delete / moderation tombstone).
Source§

fn on_community_presence( &self, chat_id: &str, npub: &str, joined: bool, event_id: &str, created_at: u64, invited_by: Option<&str>, invited_label: Option<&str>, )

A join/leave presence announcement. created_at is the authenticated inner timestamp; invited_by/invited_label carry invite attribution when present.
Source§

fn on_community_typing(&self, chat_id: &str, npub: &str, until: u64)

A Community typing indicator (ephemeral). until is the unix-secs the typer stops being active.
Source§

fn on_community_webxdc( &self, chat_id: &str, npub: &str, topic_id: &str, node_addr: Option<&str>, event_id: &str, created_at: u64, )

A WebXDC realtime peer signal. node_addr = Some advertises an Iroh node, None = peer-left.
Source§

fn on_community_self_removed(&self, community_id: &str)

The local user was removed from a Community (kick / ban / a leave authored on another device). Local data is torn down (epoch keys retained); the platform surfaces it + refreshes subs.
Source§

fn on_community_refreshed(&self, community_id: &str)

A Community’s control plane was refreshed in realtime (banlist/roles/metadata/mode change, or a re-founding followed). The platform re-reads display state.
Source§

fn on_community_dissolved(&self, community_id: &str)

A Community was DISSOLVED by its owner (CORD-02 §9): sealed read-only, held keys still open history but nothing new is honored. The platform surfaces the grave.

Auto Trait Implementations§

§

impl<'a> !Freeze for BatchingPersist<'a>

§

impl<'a> !RefUnwindSafe for BatchingPersist<'a>

§

impl<'a> !UnwindSafe for BatchingPersist<'a>

§

impl<'a> Send for BatchingPersist<'a>

§

impl<'a> Sync for BatchingPersist<'a>

§

impl<'a> Unpin for BatchingPersist<'a>

§

impl<'a> UnsafeUnpin for BatchingPersist<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more