update ical-rs

This commit is contained in:
Lennart K
2026-01-12 14:04:11 +01:00
parent 5f68a5ae5c
commit c165e761be
9 changed files with 39 additions and 43 deletions

View File

@@ -11,7 +11,7 @@ use rustical_ical::CalendarObjectType;
use rustical_store::{
Calendar, CalendarMetadata, CalendarStore, SubscriptionStore, auth::Principal,
};
use std::{collections::HashMap, io::BufReader};
use std::io::BufReader;
use tracing::instrument;
#[instrument(skip(resource_service))]
@@ -50,7 +50,7 @@ pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
cal.remove_property("X-WR-CALDESC");
cal.remove_property("X-WR-CALCOLOR");
cal.remove_property("X-WR-TIMEZONE");
let cal = cal.build(&HashMap::new()).unwrap();
let cal = cal.build(None).unwrap();
// Make sure timezone is valid
if let Some(timezone_id) = timezone_id.as_ref() {

View File

@@ -3,7 +3,6 @@ use ical::{parser::Component, property::ContentLine, types::CalDateTime};
use rustical_dav::xml::TextMatchElement;
use rustical_ical::UtcDateTime;
use rustical_xml::XmlDeserialize;
use std::collections::HashMap;
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
#[allow(dead_code)]
@@ -27,7 +26,7 @@ impl PropFilterElement {
pub fn match_property(&self, property: &ContentLine) -> bool {
if let Some(TimeRangeElement { start, end }) = &self.time_range {
// TODO: Respect timezones
let Ok(timestamp) = CalDateTime::parse_prop(property, &HashMap::default()) else {
let Ok(timestamp) = CalDateTime::parse_prop(property, None) else {
return false;
};
let timestamp = timestamp.utc();
@@ -62,13 +61,13 @@ impl PropFilterElement {
}
pub fn match_component(&self, comp: &impl Component) -> bool {
let properties = comp.get_named_properties(&self.name);
let mut properties = comp.get_named_properties(&self.name);
if self.is_not_defined.is_some() {
return properties.is_empty();
return properties.next().is_none();
}
// The filter matches when one property instance matches
// Example where this matters: We have multiple attendees and want to match one
properties.iter().any(|prop| self.match_property(prop))
properties.any(|prop| self.match_property(prop))
}
}

View File

@@ -1,5 +1,3 @@
use std::{collections::HashMap, io::BufReader};
use crate::Error;
use crate::addressbook::AddressbookResourceService;
use axum::{
@@ -12,6 +10,7 @@ use ical::{
property::ContentLine,
};
use rustical_store::{Addressbook, AddressbookStore, SubscriptionStore, auth::Principal};
use std::io::BufReader;
use tracing::instrument;
#[instrument(skip(resource_service))]
@@ -38,7 +37,7 @@ pub async fn route_import<AS: AddressbookStore, S: SubscriptionStore>(
value: Some(uuid::Uuid::new_v4().to_string()),
params: vec![].into(),
});
card = card_mut.build(&HashMap::new()).unwrap();
card = card_mut.build(None).unwrap();
}
// TODO: Make nicer
let uid = card.get_uid().unwrap();

View File

@@ -56,22 +56,22 @@ impl PropFilterElement {
}
pub fn match_component(&self, comp: &impl PropFilterable) -> bool {
let properties = comp.get_named_properties(&self.name);
let mut properties = comp.get_named_properties(&self.name);
if self.is_not_defined.is_some() {
return properties.is_empty();
return properties.next().is_none();
}
// The filter matches when one property instance matches
properties.iter().any(|prop| self.match_property(prop))
properties.any(|prop| self.match_property(prop))
}
}
pub trait PropFilterable {
fn get_named_properties(&self, name: &str) -> Vec<&ContentLine>;
fn get_named_properties<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a ContentLine>;
}
impl PropFilterable for AddressObject {
fn get_named_properties(&self, name: &str) -> Vec<&ContentLine> {
fn get_named_properties<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a ContentLine> {
self.get_vcard().get_named_properties(name)
}
}