diff --git a/aero-collections/src/calendar/mod.rs b/aero-collections/src/calendar/mod.rs index 0e0e65f..127f41b 100644 --- a/aero-collections/src/calendar/mod.rs +++ b/aero-collections/src/calendar/mod.rs @@ -1,12 +1,12 @@ pub mod namespace; -use anyhow::{anyhow, Result}; +use anyhow::{anyhow, bail, Result}; use tokio::sync::RwLock; use aero_bayou::Bayou; use aero_user::login::Credentials; -use aero_user::cryptoblob::{self, gen_key, open_deserialize, seal_serialize, Key}; -use aero_user::storage::{self, BlobRef, BlobVal, RowRef, RowVal, Selector, Store}; +use aero_user::cryptoblob::{self, gen_key, Key}; +use aero_user::storage::{self, BlobRef, BlobVal, Store}; use crate::unique_ident::*; use crate::davdag::{DavDag, IndexEntry, Token, BlobId, SyncChange}; @@ -151,10 +151,43 @@ impl CalendarInternal { } async fn delete(&mut self, blob_id: BlobId) -> Result { - todo!(); + let davstate = self.davdag.state(); + + if davstate.table.contains_key(&blob_id) { + bail!("Cannot delete event that doesn't exist"); + } + + let del_op = davstate.op_delete(blob_id); + let token = del_op.token(); + self.davdag.push(del_op).await?; + + let blob_ref = BlobRef(format!("{}/{}", self.cal_path, blob_id)); + self.storage.blob_rm(&blob_ref).await?; + + Ok(token) } async fn diff(&mut self, sync_token: Token) -> Result<(Token, Vec)> { - todo!(); + let davstate = self.davdag.state(); + + let token_changed = davstate.resolve(sync_token)?; + let changes = token_changed + .iter() + .filter_map(|t: &Token| davstate.change.get(t)) + .map(|s| s.clone()) + .collect(); + + let heads = davstate.heads_vec(); + let token = match heads.as_slice() { + [ token ] => *token, + _ => { + let op_mg = davstate.op_merge(); + let token = op_mg.token(); + self.davdag.push(op_mg).await?; + token + } + }; + + Ok((token, changes)) } } diff --git a/aero-collections/src/davdag.rs b/aero-collections/src/davdag.rs index f668831..3aaebb8 100644 --- a/aero-collections/src/davdag.rs +++ b/aero-collections/src/davdag.rs @@ -93,7 +93,7 @@ impl DavDag { } /// Resolve a sync token - pub fn resolve(&self, known: UniqueIdent) -> Result> { + pub fn resolve(&self, known: Token) -> Result> { let already_known = self.all_ancestors(known); // We can't capture all missing events if we are not connected @@ -112,7 +112,7 @@ impl DavDag { } /// Find all ancestors of a given node - fn all_ancestors(&self, known: UniqueIdent) -> OrdSet { + fn all_ancestors(&self, known: Token) -> OrdSet { let mut all_known: OrdSet = OrdSet::new(); let mut to_collect = vec![known]; loop { diff --git a/aero-collections/src/mail/mailbox.rs b/aero-collections/src/mail/mailbox.rs index f797be6..fcdb21e 100644 --- a/aero-collections/src/mail/mailbox.rs +++ b/aero-collections/src/mail/mailbox.rs @@ -375,7 +375,7 @@ impl MailboxInternal { async fn delete(&mut self, ident: UniqueIdent) -> Result<()> { if !self.uid_index.state().table.contains_key(&ident) { - bail!("Cannot delete mail that doesn't exit"); + bail!("Cannot delete mail that doesn't exist"); } let del_mail_op = self.uid_index.state().op_mail_del(ident);