pub struct MessageRepository { /* private fields */ }Expand description
A tree of messages with one selected path, root to head.
Implementations§
Source§impl MessageRepository
impl MessageRepository
Sourcepub fn canonical_head_id(&self) -> Option<&MessageId>
pub fn canonical_head_id(&self) -> Option<&MessageId>
The head after skipping optimistic messages.
Sourcepub fn messages(&self) -> Arc<[Arc<ThreadMessage>]> ⓘ
pub fn messages(&self) -> Arc<[Arc<ThreadMessage>]> ⓘ
The selected path from the root to the head.
Sourcepub fn messages_to(
&self,
head_id: &MessageId,
) -> Result<Vec<Arc<ThreadMessage>>, RepositoryError>
pub fn messages_to( &self, head_id: &MessageId, ) -> Result<Vec<Arc<ThreadMessage>>, RepositoryError>
The path from the root to head_id.
Sourcepub fn get(&self, id: &MessageId) -> Result<MessageEntry, RepositoryError>
pub fn get(&self, id: &MessageId) -> Result<MessageEntry, RepositoryError>
A message with its parent and depth.
Sourcepub fn has_children(&self, id: &MessageId) -> bool
pub fn has_children(&self, id: &MessageId) -> bool
Whether the message has replies.
Sourcepub fn branches(&self, id: &MessageId) -> Result<&[MessageId], RepositoryError>
pub fn branches(&self, id: &MessageId) -> Result<&[MessageId], RepositoryError>
The ids of the message and its siblings, in creation order.
Sourcepub fn branch_position(
&self,
id: &MessageId,
) -> Result<(usize, usize), RepositoryError>
pub fn branch_position( &self, id: &MessageId, ) -> Result<(usize, usize), RepositoryError>
(position, count) of the message among its siblings, 1-based, without
allocating (what a branch picker shows).
Sourcepub fn message_changes_since(&self, version: Option<u64>) -> MessageChanges
pub fn message_changes_since(&self, version: Option<u64>) -> MessageChanges
Selected-message changes since version, with bounded bookkeeping.
Call messages for a full read when indices is
None. A consumer must also refresh global runtime state (running,
capabilities), which is not part of this repository’s journal.
Sourcepub fn shape_version(&self) -> u64
pub fn shape_version(&self) -> u64
Changes whenever messages are added, moved or removed, or the selected path changes; not when a message is updated in place (streaming). While it is unchanged, every message keeps its branch position.
Sourcepub fn add_or_update(
&mut self,
parent_id: Option<&MessageId>,
message: impl Into<Arc<ThreadMessage>>,
) -> Result<(), RepositoryError>
pub fn add_or_update( &mut self, parent_id: Option<&MessageId>, message: impl Into<Arc<ThreadMessage>>, ) -> Result<(), RepositoryError>
Insert a new message after parent_id, or replace the stored message
with the same id, moving it under parent_id if that changed.
Sourcepub fn delete(
&mut self,
id: &MessageId,
replacement: Option<Option<&MessageId>>,
) -> Result<(), RepositoryError>
pub fn delete( &mut self, id: &MessageId, replacement: Option<Option<&MessageId>>, ) -> Result<(), RepositoryError>
Remove a message. Its children move to replacement: by default its
parent, Some(None) for the root, or Some(Some(id)) for another message.
Sourcepub fn switch_to_branch(
&mut self,
id: &MessageId,
) -> Result<(), RepositoryError>
pub fn switch_to_branch( &mut self, id: &MessageId, ) -> Result<(), RepositoryError>
Make the branch through id current, selecting its last-used descendants.
Sourcepub fn reset_head(
&mut self,
id: Option<&MessageId>,
) -> Result<(), RepositoryError>
pub fn reset_head( &mut self, id: Option<&MessageId>, ) -> Result<(), RepositoryError>
Make id the head and delete everything below it; None clears all.
Sourcepub fn export(&self) -> ExportedRepository
pub fn export(&self) -> ExportedRepository
Persisted messages in parent-first order; optimistic ones are skipped and their children reattached to the nearest persisted ancestor.
Sourcepub fn import(
&mut self,
exported: ExportedRepository,
) -> Result<(), RepositoryError>
pub fn import( &mut self, exported: ExportedRepository, ) -> Result<(), RepositoryError>
Add or update every listed message (parents first), then select the listed head, or the last listed message.