diff --git a/crates/store/src/calendar_store.rs b/crates/store/src/calendar_store.rs index 99b9c4e..0c51909 100644 --- a/crates/store/src/calendar_store.rs +++ b/crates/store/src/calendar_store.rs @@ -77,13 +77,23 @@ pub trait CalendarStore: Send + Sync + 'static { object_id: &str, show_deleted: bool, ) -> Result; + async fn put_objects( + &self, + principal: String, + cal_id: String, + objects: Vec, + overwrite: bool, + ) -> Result<(), Error>; async fn put_object( &self, principal: String, cal_id: String, object: CalendarObject, overwrite: bool, - ) -> Result<(), Error>; + ) -> Result<(), Error> { + self.put_objects(principal, cal_id, vec![object], overwrite) + .await + } async fn delete_object( &self, principal: &str, diff --git a/crates/store/src/combined_calendar_store.rs b/crates/store/src/combined_calendar_store.rs index d90130a..a83b7e4 100644 --- a/crates/store/src/combined_calendar_store.rs +++ b/crates/store/src/combined_calendar_store.rs @@ -147,15 +147,15 @@ impl CalendarStore for CombinedCalendarStore { .await } - async fn put_object( + async fn put_objects( &self, principal: String, cal_id: String, - object: rustical_ical::CalendarObject, + objects: Vec, overwrite: bool, ) -> Result<(), crate::Error> { self.store_for_id(&cal_id) - .put_object(principal, cal_id, object, overwrite) + .put_objects(principal, cal_id, objects, overwrite) .await } diff --git a/crates/store_sqlite/src/addressbook_store/birthday_calendar.rs b/crates/store_sqlite/src/addressbook_store/birthday_calendar.rs index 4ca06a5..8a73824 100644 --- a/crates/store_sqlite/src/addressbook_store/birthday_calendar.rs +++ b/crates/store_sqlite/src/addressbook_store/birthday_calendar.rs @@ -394,11 +394,11 @@ impl CalendarStore for SqliteAddressbookStore { } #[instrument] - async fn put_object( + async fn put_objects( &self, _principal: String, _cal_id: String, - _object: CalendarObject, + _objects: Vec, _overwrite: bool, ) -> Result<(), Error> { Err(Error::ReadOnly) diff --git a/crates/store_sqlite/src/calendar_store.rs b/crates/store_sqlite/src/calendar_store.rs index 780ce3a..ea4d2a8 100644 --- a/crates/store_sqlite/src/calendar_store.rs +++ b/crates/store_sqlite/src/calendar_store.rs @@ -776,11 +776,11 @@ impl CalendarStore for SqliteCalendarStore { } #[instrument] - async fn put_object( + async fn put_objects( &self, principal: String, cal_id: String, - object: CalendarObject, + objects: Vec, overwrite: bool, ) -> Result<(), Error> { let mut tx = self @@ -789,33 +789,37 @@ impl CalendarStore for SqliteCalendarStore { .await .map_err(crate::Error::from)?; - let object_id = object.get_id().to_owned(); - let calendar = Self::_get_calendar(&mut *tx, &principal, &cal_id, true).await?; if calendar.subscription_url.is_some() { // We cannot commit an object to a subscription calendar return Err(Error::ReadOnly); } - Self::_put_object(&mut *tx, &principal, &cal_id, &object, overwrite).await?; - - let sync_token = Self::log_object_operation( - &mut tx, - &principal, - &cal_id, - &object_id, - ChangeOperation::Add, - ) - .await?; + let mut sync_token = None; + for object in objects { + sync_token = Some( + Self::log_object_operation( + &mut tx, + &principal, + &cal_id, + object.get_id(), + ChangeOperation::Add, + ) + .await?, + ); + Self::_put_object(&mut *tx, &principal, &cal_id, &object, overwrite).await?; + } tx.commit().await.map_err(crate::Error::from)?; - self.send_push_notification( - CollectionOperationInfo::Content { sync_token }, - self.get_calendar(&principal, &cal_id, true) - .await? - .push_topic, - ); + if let Some(sync_token) = sync_token { + self.send_push_notification( + CollectionOperationInfo::Content { sync_token }, + self.get_calendar(&principal, &cal_id, true) + .await? + .push_topic, + ); + } Ok(()) }