pub struct MessagingStorage { /* private fields */ }Expand description
Wraps a single SQLite connection guarded by a std::sync::Mutex. The
daemon serializes writes through the mutex, which is acceptable for the
expected message volume (interactive chat).
Implementations§
Source§impl MessagingStorage
impl MessagingStorage
Sourcepub fn open(path: PathBuf) -> Result<Self>
pub fn open(path: PathBuf) -> Result<Self>
Open or create the database file and apply the canonical schema.
Sourcepub fn insert_message(&self, m: &MessageRecord) -> Result<()>
pub fn insert_message(&self, m: &MessageRecord) -> Result<()>
Persist a brand-new message row. Caller is responsible for choosing
the appropriate initial status (Pending for outbound, Delivered
for inbound).
Sourcepub fn bump_conversation_after_local_send(
&self,
peer_id_hex: &str,
message_id_hex: &str,
ts_ms: i64,
body: &str,
) -> Result<()>
pub fn bump_conversation_after_local_send( &self, peer_id_hex: &str, message_id_hex: &str, ts_ms: i64, body: &str, ) -> Result<()>
Refresh the conversations_meta row after a local outbound send.
Sourcepub fn bump_conversation_after_remote_receive(
&self,
peer_id_hex: &str,
message_id_hex: &str,
ts_ms: i64,
body: &str,
) -> Result<ConversationBump>
pub fn bump_conversation_after_remote_receive( &self, peer_id_hex: &str, message_id_hex: &str, ts_ms: i64, body: &str, ) -> Result<ConversationBump>
Refresh the conversations_meta row after an inbound message and
return the resulting partial summary (the service layer fills in
name and x25519_pubkey from the peer directory).
Sourcepub fn set_message_status(
&self,
message_id_hex: &str,
status: MessageStatus,
delivered_at_ms: Option<i64>,
read_at_ms: Option<i64>,
) -> Result<()>
pub fn set_message_status( &self, message_id_hex: &str, status: MessageStatus, delivered_at_ms: Option<i64>, read_at_ms: Option<i64>, ) -> Result<()>
Update the lifecycle status of an existing outbound message and the optional delivered/read timestamps.
Sourcepub fn set_message_failed(
&self,
message_id_hex: &str,
reason: &str,
at_ms: i64,
) -> Result<()>
pub fn set_message_failed( &self, message_id_hex: &str, reason: &str, at_ms: i64, ) -> Result<()>
Set status = failed and persist a human-readable reason.
Sourcepub fn history(
&self,
peer_id_hex: &str,
before_ts_ms: Option<i64>,
limit: i64,
) -> Result<(Vec<MessageRecord>, bool)>
pub fn history( &self, peer_id_hex: &str, before_ts_ms: Option<i64>, limit: i64, ) -> Result<(Vec<MessageRecord>, bool)>
Page through a peer’s history newest-first.
Sourcepub fn list_conversations_raw(&self) -> Result<Vec<ConversationSummary>>
pub fn list_conversations_raw(&self) -> Result<Vec<ConversationSummary>>
Snapshot of all conversations, sorted by most-recent activity.
name and x25519_pubkey are left blank/None — the service
layer fills them in from the daemon’s peer directory.
Sourcepub fn delete_conversation(&self, peer_id_hex: &str) -> Result<(usize, bool)>
pub fn delete_conversation(&self, peer_id_hex: &str) -> Result<(usize, bool)>
Atomic per-peer wipe of messages and conversations_meta.
Returns (deleted_messages, deleted_conversation) so the caller
can report exact counts to the RPC client.
Sourcepub fn delete_all_messages(&self) -> Result<(usize, usize)>
pub fn delete_all_messages(&self) -> Result<(usize, usize)>
Atomic global wipe of every message + conversation row.
Sourcepub fn mark_read_up_to(
&self,
peer_id_hex: &str,
up_to_ts_ms: i64,
) -> Result<i64>
pub fn mark_read_up_to( &self, peer_id_hex: &str, up_to_ts_ms: i64, ) -> Result<i64>
Mark every message at-or-before up_to_ts_ms as read for the peer.
Returns the new unread_count (always 0).
Sourcepub fn delete_conversation_for_peer(
&self,
peer: &NodeId,
) -> Result<(usize, bool)>
pub fn delete_conversation_for_peer( &self, peer: &NodeId, ) -> Result<(usize, bool)>
Convenience wrapper used by crate::service::MessagingService
when handling an on_peer_forgotten lifecycle event. Equivalent
to Self::delete_conversation but keyed by NodeId instead of
the hex projection.