export: Include vtimezones

fixes #112
This commit is contained in:
Lennart
2025-08-22 21:32:34 +02:00
parent 9decef093d
commit 9c114dc204
2 changed files with 20 additions and 0 deletions

View File

@@ -37,6 +37,7 @@ pub async fn route_get<C: CalendarStore, S: SubscriptionStore>(
.await?;
let mut timezones = HashMap::new();
let mut vtimezones = HashMap::new();
let objects = cal_store.get_objects(&principal, &calendar_id).await?;
let mut ical_calendar_builder = IcalCalendarBuilder::version("4.0")
@@ -65,6 +66,7 @@ pub async fn route_get<C: CalendarStore, S: SubscriptionStore>(
}
for object in &objects {
vtimezones.extend(object.get_vtimezones());
match object.get_data() {
CalendarObjectComponent::Event(EventObject {
event,
@@ -83,6 +85,10 @@ pub async fn route_get<C: CalendarStore, S: SubscriptionStore>(
}
}
for vtimezone in vtimezones.into_values() {
ical_calendar_builder = ical_calendar_builder.add_tz(vtimezone.to_owned());
}
let ical_calendar = ical_calendar_builder
.build()
.map_err(|parser_error| Error::IcalError(parser_error.into()))?;

View File

@@ -5,6 +5,7 @@ use chrono::DateTime;
use chrono::Utc;
use derive_more::Display;
use ical::generator::{Emitter, IcalCalendar};
use ical::parser::ical::component::IcalTimeZone;
use ical::property::Property;
use serde::Deserialize;
use serde::Serialize;
@@ -71,6 +72,7 @@ pub struct CalendarObject {
data: CalendarObjectComponent,
properties: Vec<Property>,
ics: String,
vtimezones: HashMap<String, IcalTimeZone>,
}
impl CalendarObject {
@@ -102,6 +104,13 @@ impl CalendarObject {
.map(|timezone| (timezone.get_tzid().to_owned(), (&timezone).try_into().ok()))
.collect();
let vtimezones = cal
.timezones
.clone()
.into_iter()
.map(|timezone| (timezone.get_tzid().to_owned(), timezone))
.collect();
let data = if let Some(event) = cal.events.into_iter().next() {
CalendarObjectComponent::Event(EventObject { event, timezones })
} else if let Some(todo) = cal.todos.into_iter().next() {
@@ -118,9 +127,14 @@ impl CalendarObject {
data,
properties: cal.properties,
ics,
vtimezones,
})
}
pub fn get_vtimezones(&self) -> &HashMap<String, IcalTimeZone> {
&self.vtimezones
}
pub fn get_data(&self) -> &CalendarObjectComponent {
&self.data
}