diff --git a/src/remote.rs b/src/remote.rs index dca451c..f097660 100644 --- a/src/remote.rs +++ b/src/remote.rs @@ -26,7 +26,7 @@ pub trait RemoteSync : AuthStorage+MemoStorage+Sized { }))? .into_reader(); - let mut data: Vec = vec![0; 0]; + let mut data: Vec = Vec::new(); resp.read_to_end(&mut data)?; // TODO decrypt @@ -35,7 +35,7 @@ pub trait RemoteSync : AuthStorage+MemoStorage+Sized { return Ok(self.merge(&other).unwrap()); } - fn merge(&mut self, other: &Self) -> Result { // TODO don't use error specific to rusqlite + fn merge(&mut self, other: &Self) -> Result { let mut count = 0; let mut memo_ids : HashSet = HashSet::new(); for memo in self.all(false)?.iter() { @@ -47,7 +47,10 @@ pub trait RemoteSync : AuthStorage+MemoStorage+Sized { for memo in other.all(true)?.iter() { if memo_ids.contains(&memo.id) { - self.set(memo)?; // TODO only replace if more recently edited!! + let old_memo = self.get(&memo.id)?; + if memo.last_edit > old_memo.last_edit { + self.set(memo)?; + } } else { self.insert(memo.clone())?; count += 1;