|
|
|
|
@ -36,19 +36,41 @@ impl CachedCalendar {
|
|
|
|
|
self.mock_behaviour = mock_behaviour; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Add an item
|
|
|
|
|
async fn regular_add_item(&mut self, item: Item) -> Result<SyncStatus, Box<dyn Error>> { |
|
|
|
|
// TODO: here (and in the remote version, display an errror in case we overwrite something?)
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "local_calendar_mocks_remote_calendars")] |
|
|
|
|
async fn add_item_maybe_mocked(&mut self, item: Item) -> Result<SyncStatus, Box<dyn Error>> { |
|
|
|
|
self.mock_behaviour.as_ref().map_or(Ok(()), |b| b.lock().unwrap().can_add_item())?; |
|
|
|
|
|
|
|
|
|
if self.mock_behaviour.is_some() { |
|
|
|
|
self.add_or_update_item_force_synced(item).await |
|
|
|
|
} else { |
|
|
|
|
self.regular_add_or_update_item(item).await |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[cfg(feature = "local_calendar_mocks_remote_calendars")] |
|
|
|
|
async fn update_item_maybe_mocked(&mut self, item: Item) -> Result<SyncStatus, Box<dyn Error>> { |
|
|
|
|
self.mock_behaviour.as_ref().map_or(Ok(()), |b| b.lock().unwrap().can_update_item())?; |
|
|
|
|
|
|
|
|
|
if self.mock_behaviour.is_some() { |
|
|
|
|
self.add_or_update_item_force_synced(item).await |
|
|
|
|
} else { |
|
|
|
|
self.regular_add_or_update_item(item).await |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Add or update an item
|
|
|
|
|
async fn regular_add_or_update_item(&mut self, item: Item) -> Result<SyncStatus, Box<dyn Error>> { |
|
|
|
|
let ss_clone = item.sync_status().clone(); |
|
|
|
|
log::debug!("Adding an item with {:?}", ss_clone); |
|
|
|
|
log::debug!("Adding or updating an item with {:?}", ss_clone); |
|
|
|
|
self.items.insert(item.id().clone(), item); |
|
|
|
|
Ok(ss_clone) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Add an item, but force a "synced" SyncStatus. This is the typical behaviour on a remote calendar
|
|
|
|
|
/// Add or update an item, but force a "synced" SyncStatus. This is the normal behaviour that would happen on a server
|
|
|
|
|
#[cfg(feature = "local_calendar_mocks_remote_calendars")] |
|
|
|
|
async fn add_item_force_synced(&mut self, mut item: Item) -> Result<SyncStatus, Box<dyn Error>> { |
|
|
|
|
log::debug!("Adding an item, but forces a synced SyncStatus"); |
|
|
|
|
async fn add_or_update_item_force_synced(&mut self, mut item: Item) -> Result<SyncStatus, Box<dyn Error>> { |
|
|
|
|
log::debug!("Adding or updating an item, but forces a synced SyncStatus"); |
|
|
|
|
match item.sync_status() { |
|
|
|
|
SyncStatus::Synced(_) => (), |
|
|
|
|
_ => item.set_sync_status(SyncStatus::random_synced()), |
|
|
|
|
@ -108,20 +130,26 @@ impl BaseCalendar for CachedCalendar {
|
|
|
|
|
self.supported_components |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[cfg(not(feature = "local_calendar_mocks_remote_calendars"))] |
|
|
|
|
async fn add_item(&mut self, item: Item) -> Result<SyncStatus, Box<dyn Error>> { |
|
|
|
|
self.regular_add_item(item).await |
|
|
|
|
if self.items.contains_key(item.id()) { |
|
|
|
|
return Err(format!("Item {:?} cannot be added, it exists already", item.id()).into()); |
|
|
|
|
} |
|
|
|
|
#[cfg(feature = "local_calendar_mocks_remote_calendars")] |
|
|
|
|
async fn add_item(&mut self, item: Item) -> Result<SyncStatus, Box<dyn Error>> { |
|
|
|
|
#[cfg(not(feature = "local_calendar_mocks_remote_calendars"))] |
|
|
|
|
return self.regular_add_or_update_item(item).await; |
|
|
|
|
|
|
|
|
|
#[cfg(feature = "local_calendar_mocks_remote_calendars")] |
|
|
|
|
self.mock_behaviour.as_ref().map_or(Ok(()), |b| b.lock().unwrap().can_add_item())?; |
|
|
|
|
return self.add_item_maybe_mocked(item).await; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if self.mock_behaviour.is_some() { |
|
|
|
|
self.add_item_force_synced(item).await |
|
|
|
|
} else { |
|
|
|
|
self.regular_add_item(item).await |
|
|
|
|
async fn update_item(&mut self, item: Item) -> Result<SyncStatus, Box<dyn Error>> { |
|
|
|
|
if self.items.contains_key(item.id()) == false { |
|
|
|
|
return Err(format!("Item {:?} cannot be updated, it does not already exist", item.id()).into()); |
|
|
|
|
} |
|
|
|
|
#[cfg(not(feature = "local_calendar_mocks_remote_calendars"))] |
|
|
|
|
return self.regular_add_or_update_item(item).await; |
|
|
|
|
|
|
|
|
|
#[cfg(feature = "local_calendar_mocks_remote_calendars")] |
|
|
|
|
return self.update_item_maybe_mocked(item).await; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|