From af0b36a1532311669303dc8134bf74e2d607ef0c Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 3 Nov 2026 06:46:44 +0100 Subject: writers from authors --- src/document/changes.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/document') diff --git a/src/document/changes.rs b/src/document/changes.rs index 92b7744..faba895 100644 --- a/src/document/changes.rs +++ b/src/document/changes.rs @@ -27,6 +27,28 @@ pub(crate) fn commit_times(doc: &Document, since: &[ChangeHash]) -> Vec { .collect() } +/// Who wrote the changes after `since`: the authors their writers set (a node's ID, +/// `replica::authored`), each once; and whether any change has none (a snapshot, or a +/// change of a node that set none). +pub(crate) fn authors_since(doc: &Document, since: &[ChangeHash]) -> (Vec, bool) { + let mut authors: Vec = Vec::new(); + let mut unknown = false; + for change in doc.get_changes_meta(since) { + match change + .author + .as_ref() + .and_then(|author| std::str::from_utf8(author.as_bytes()).ok()) + { + Some(author) if !authors.iter().any(|known| known == author) => { + authors.push(author.to_owned()); + } + Some(_) => {} + None => unknown = true, + } + } + (authors, unknown) +} + /// The change `hash` as the document encodes it; None if `doc` doesn't have it. pub(crate) fn change_bytes(doc: &Document, hash: &ChangeHash) -> Option> { doc.get_change_by_hash(hash) -- cgit v1.3.1