diff options
Diffstat (limited to 'src/document/changes.rs')
| -rw-r--r-- | src/document/changes.rs | 22 |
1 files changed, 22 insertions, 0 deletions
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<i64> { .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<String>, bool) { + let mut authors: Vec<String> = 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<Vec<u8>> { doc.get_change_by_hash(hash) |
