build MVP for birthday calendar

This commit is contained in:
Lennart K
2026-01-13 12:41:03 +01:00
parent 7eecd95757
commit 5ec2787ecf
5 changed files with 172 additions and 58 deletions

View File

@@ -279,7 +279,7 @@ impl CalendarStore for SqliteAddressbookStore {
.strip_prefix(BIRTHDAYS_PREFIX)
.ok_or(Error::NotFound)?
.to_string();
Self::_update_birthday_calendar(&self.db, &principal, &calendar).await
Self::_update_birthday_calendar(&self.db, principal, &calendar).await
}
#[instrument]
@@ -330,14 +330,29 @@ impl CalendarStore for SqliteAddressbookStore {
.ok_or(Error::NotFound)?;
let (objects, deleted_objects, new_synctoken) =
AddressbookStore::sync_changes(self, principal, cal_id, synctoken).await?;
todo!();
// let objects: Result<Vec<Option<CalendarObject>>, rustical_ical::Error> = objects
// .iter()
// .map(AddressObject::get_birthday_object)
// .collect();
// let objects = objects?.into_iter().flatten().collect();
//
// Ok((objects, deleted_objects, new_synctoken))
let mut out_objects = vec![];
for (object_id, object) in objects {
if let Some(birthday) = object.get_birthday_object()? {
out_objects.push((format!("{object_id}-birthday"), birthday));
}
if let Some(anniversary) = object.get_anniversary_object()? {
out_objects.push((format!("{object_id}-anniversayr"), anniversary));
}
}
let deleted_objects = deleted_objects
.into_iter()
.flat_map(|object_id| {
[
format!("{object_id}-birthday"),
format!("{object_id}-anniversary"),
]
})
.collect();
Ok((out_objects, deleted_objects, new_synctoken))
}
#[instrument]
@@ -358,22 +373,19 @@ impl CalendarStore for SqliteAddressbookStore {
principal: &str,
cal_id: &str,
) -> Result<Vec<(String, CalendarObject)>, Error> {
todo!()
// let cal_id = cal_id
// .strip_prefix(BIRTHDAYS_PREFIX)
// .ok_or(Error::NotFound)?;
// let objects: Result<Vec<HashMap<&'static str, CalendarObject>>, rustical_ical::Error> =
// AddressbookStore::get_objects(self, principal, cal_id)
// .await?
// .iter()
// .map(AddressObject::get_significant_dates)
// .collect();
// let objects = objects?
// .into_iter()
// .flat_map(HashMap::into_values)
// .collect();
//
// Ok(objects)
let mut objects = vec![];
let cal_id = cal_id
.strip_prefix(BIRTHDAYS_PREFIX)
.ok_or(Error::NotFound)?;
for (object_id, object) in AddressbookStore::get_objects(self, principal, cal_id).await? {
if let Some(birthday) = object.get_birthday_object()? {
objects.push((format!("{object_id}-birthday"), birthday));
}
if let Some(anniversary) = object.get_anniversary_object()? {
objects.push((format!("{object_id}-anniversayr"), anniversary));
}
}
Ok(objects)
}
#[instrument]
@@ -388,11 +400,14 @@ impl CalendarStore for SqliteAddressbookStore {
.strip_prefix(BIRTHDAYS_PREFIX)
.ok_or(Error::NotFound)?;
let (addressobject_id, date_type) = object_id.rsplit_once('-').ok_or(Error::NotFound)?;
AddressbookStore::get_object(self, principal, cal_id, addressobject_id, show_deleted)
.await?
.get_significant_dates()?
.remove(date_type)
.ok_or(Error::NotFound)
let obj =
AddressbookStore::get_object(self, principal, cal_id, addressobject_id, show_deleted)
.await?;
match date_type {
"birthday" => Ok(obj.get_birthday_object()?.ok_or(Error::NotFound)?),
"anniversary" => Ok(obj.get_anniversary_object()?.ok_or(Error::NotFound)?),
_ => Err(Error::NotFound),
}
}
#[instrument]

View File

@@ -509,7 +509,7 @@ impl AddressbookStore for SqliteAddressbookStore {
) -> Result<(), rustical_store::Error> {
assert_eq!(principal, &addressbook.principal);
assert_eq!(id, &addressbook.id);
Self::_update_addressbook(&self.db, &principal, &id, &addressbook).await
Self::_update_addressbook(&self.db, principal, id, &addressbook).await
}
#[instrument]
@@ -648,9 +648,9 @@ impl AddressbookStore for SqliteAddressbookStore {
let sync_token = Self::log_object_operation(
&mut tx,
&principal,
&addressbook_id,
&object_id,
principal,
addressbook_id,
object_id,
ChangeOperation::Add,
)
.await

View File

@@ -880,7 +880,7 @@ impl CalendarStore for SqliteCalendarStore {
.await
.map_err(crate::Error::from)?;
let calendar = Self::_get_calendar(&mut *tx, &principal, &cal_id, true).await?;
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);
@@ -891,17 +891,14 @@ impl CalendarStore for SqliteCalendarStore {
sync_token = Some(
Self::log_object_operation(
&mut tx,
&principal,
&cal_id,
principal,
cal_id,
&object_id,
ChangeOperation::Add,
)
.await?,
);
Self::_put_object(
&mut *tx, &principal, &cal_id, &object_id, &object, overwrite,
)
.await?;
Self::_put_object(&mut *tx, principal, cal_id, &object_id, &object, overwrite).await?;
}
tx.commit().await.map_err(crate::Error::from)?;
@@ -909,9 +906,7 @@ impl CalendarStore for SqliteCalendarStore {
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,
self.get_calendar(principal, cal_id, true).await?.push_topic,
);
}
Ok(())