caldav: Make supported-calendar-component-set configurable

This commit is contained in:
Lennart
2025-01-19 13:19:46 +01:00
parent 79edfcaa25
commit 3b99508065
14 changed files with 252 additions and 71 deletions

View File

@@ -1,3 +1,4 @@
use super::CalendarObjectType;
use crate::synctoken::format_synctoken;
use chrono::NaiveDateTime;
use serde::Serialize;
@@ -16,6 +17,7 @@ pub struct Calendar {
pub synctoken: i64,
pub subscription_url: Option<String>,
pub push_topic: String,
pub components: Vec<CalendarObjectType>,
}
impl Calendar {

View File

@@ -2,10 +2,11 @@ use super::{CalDateTime, EventObject, JournalObject, TodoObject};
use crate::Error;
use anyhow::Result;
use ical::parser::{ical::component::IcalTimeZone, Component};
use serde::Serialize;
use sha2::{Digest, Sha256};
use std::{collections::HashMap, io::BufReader};
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
// specified in https://datatracker.ietf.org/doc/html/rfc5545#section-3.6
pub enum CalendarObjectType {
Event = 0,
@@ -13,6 +14,31 @@ pub enum CalendarObjectType {
Journal = 2,
}
impl rustical_xml::ValueSerialize for CalendarObjectType {
fn serialize(&self) -> String {
match self {
CalendarObjectType::Event => "VEVENT",
CalendarObjectType::Todo => "VTODO",
CalendarObjectType::Journal => "VJOURNAL",
}
.to_owned()
}
}
impl rustical_xml::ValueDeserialize for CalendarObjectType {
fn deserialize(val: &str) -> std::result::Result<Self, rustical_xml::XmlError> {
match <String as rustical_xml::ValueDeserialize>::deserialize(val)?.as_str() {
"VEVENT" => Ok(Self::Event),
"VTODO" => Ok(Self::Todo),
"VJOURNAL" => Ok(Self::Journal),
_ => Err(rustical_xml::XmlError::Other(format!(
"Invalid value '{}', must be VEVENT, VTODO, or VJOURNAL",
val
))),
}
}
}
#[derive(Debug, Clone)]
pub enum CalendarObjectComponent {
Event(EventObject),

View File

@@ -1,7 +1,8 @@
use std::sync::Arc;
use crate::{
AddressObject, Addressbook, AddressbookStore, Calendar, CalendarObject, CalendarStore, Error,
calendar::CalendarObjectType, AddressObject, Addressbook, AddressbookStore, Calendar,
CalendarObject, CalendarStore, Error,
};
use async_trait::async_trait;
use derive_more::derive::Constructor;
@@ -31,6 +32,7 @@ fn birthday_calendar(addressbook: Addressbook) -> Calendar {
hasher.update(addressbook.push_topic);
format!("{:x}", hasher.finalize())
},
components: vec![CalendarObjectType::Event],
}
}