Added find_deletions and fixed sync
This commit is contained in:
parent
4cc882039b
commit
41502271ff
3 changed files with 34 additions and 22 deletions
|
@ -92,6 +92,12 @@ impl PartialCalendar for CachedCalendar {
|
||||||
map
|
map
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_item_ids(&mut self) -> Vec<ItemId> {
|
||||||
|
self.items.iter()
|
||||||
|
.map(|item| item.id().clone())
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
fn get_item_by_id_mut(&mut self, id: &ItemId) -> Option<&mut Item> {
|
fn get_item_by_id_mut(&mut self, id: &ItemId) -> Option<&mut Item> {
|
||||||
for item in &mut self.items {
|
for item in &mut self.items {
|
||||||
if item.id() == id {
|
if item.id() == id {
|
||||||
|
@ -100,10 +106,6 @@ impl PartialCalendar for CachedCalendar {
|
||||||
}
|
}
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_missing_items_compared_to(&self, _other: &dyn PartialCalendar) -> Vec<ItemId> {
|
|
||||||
unimplemented!("todo");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CompleteCalendar for CachedCalendar {
|
impl CompleteCalendar for CachedCalendar {
|
||||||
|
|
|
@ -72,9 +72,8 @@ where
|
||||||
Some(cal) => cal,
|
Some(cal) => cal,
|
||||||
};
|
};
|
||||||
|
|
||||||
let server_mod = cal_server.get_items_modified_since(last_sync, None);
|
|
||||||
let server_del = match last_sync {
|
let server_del = match last_sync {
|
||||||
Some(_date) => cal_server.find_missing_items_compared_to(cal_local),
|
Some(_date) => cal_server.find_deletions(cal_local.get_item_ids()),
|
||||||
None => Vec::new(),
|
None => Vec::new(),
|
||||||
};
|
};
|
||||||
let local_del = match last_sync {
|
let local_del = match last_sync {
|
||||||
|
@ -88,6 +87,7 @@ where
|
||||||
for deleted_id in server_del {
|
for deleted_id in server_del {
|
||||||
tasks_id_to_remove_from_local.push(deleted_id);
|
tasks_id_to_remove_from_local.push(deleted_id);
|
||||||
}
|
}
|
||||||
|
let server_mod = cal_server.get_items_modified_since(last_sync, None);
|
||||||
for (new_id, new_item) in &server_mod {
|
for (new_id, new_item) in &server_mod {
|
||||||
if server_mod.contains_key(new_id) {
|
if server_mod.contains_key(new_id) {
|
||||||
log::warn!("Conflict for task {} ({}). Using the server version.", new_item.name(), new_id);
|
log::warn!("Conflict for task {} ({}). Using the server version.", new_item.name(), new_id);
|
||||||
|
|
|
@ -54,6 +54,9 @@ pub trait PartialCalendar {
|
||||||
fn get_items_modified_since(&self, since: Option<DateTime<Utc>>, filter: Option<crate::calendar::SearchFilter>)
|
fn get_items_modified_since(&self, since: Option<DateTime<Utc>>, filter: Option<crate::calendar::SearchFilter>)
|
||||||
-> HashMap<ItemId, &Item>;
|
-> HashMap<ItemId, &Item>;
|
||||||
|
|
||||||
|
/// Get the IDs of all current items in this calendar
|
||||||
|
fn get_item_ids(&mut self) -> Vec<ItemId>;
|
||||||
|
|
||||||
/// Returns a particular item
|
/// Returns a particular item
|
||||||
fn get_item_by_id_mut(&mut self, id: &ItemId) -> Option<&mut Item>;
|
fn get_item_by_id_mut(&mut self, id: &ItemId) -> Option<&mut Item>;
|
||||||
|
|
||||||
|
@ -63,9 +66,29 @@ pub trait PartialCalendar {
|
||||||
/// Remove an item from this calendar
|
/// Remove an item from this calendar
|
||||||
fn delete_item(&mut self, item_id: &ItemId);
|
fn delete_item(&mut self, item_id: &ItemId);
|
||||||
|
|
||||||
/// Compares with another calendar and lists missing items
|
|
||||||
/// This function is a sort of replacement for `get_items_deleted_since`, that is not available on PartialCalendars
|
/// Returns whether this calDAV calendar supports to-do items
|
||||||
fn find_missing_items_compared_to(&self, other: &dyn PartialCalendar) -> Vec<ItemId>;
|
fn supports_todo(&self) -> bool {
|
||||||
|
self.supported_components().contains(crate::calendar::SupportedComponents::TODO)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns whether this calDAV calendar supports calendar items
|
||||||
|
fn supports_events(&self) -> bool {
|
||||||
|
self.supported_components().contains(crate::calendar::SupportedComponents::EVENT)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Finds the IDs of the items that are missing compared to a reference set
|
||||||
|
fn find_deletions(&mut self, reference_set: Vec<ItemId>) -> Vec<ItemId> {
|
||||||
|
let mut deletions = Vec::new();
|
||||||
|
|
||||||
|
let current_items = self.get_item_ids();
|
||||||
|
for original_item in reference_set {
|
||||||
|
if current_items.contains(&original_item) == false {
|
||||||
|
deletions.push(original_item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deletions
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A calendar we always know everything about.
|
/// A calendar we always know everything about.
|
||||||
|
@ -81,16 +104,3 @@ pub trait CompleteCalendar : PartialCalendar {
|
||||||
fn get_items(&self) -> HashMap<ItemId, &Item>;
|
fn get_items(&self) -> HashMap<ItemId, &Item>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl PartialCalendar {
|
|
||||||
/// Returns whether this calDAV calendar supports to-do items
|
|
||||||
pub fn supports_todo(&self) -> bool {
|
|
||||||
self.supported_components().contains(crate::calendar::SupportedComponents::TODO)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns whether this calDAV calendar supports calendar items
|
|
||||||
pub fn supports_events(&self) -> bool {
|
|
||||||
self.supported_components().contains(crate::calendar::SupportedComponents::EVENT)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue