JMAP for Calendars implementation (part 2)

This commit is contained in:
mdecimus
2025-10-07 19:06:49 +02:00
parent b7df05dd3b
commit 2fb59edaa7
22 changed files with 1809 additions and 330 deletions

View File

@@ -87,6 +87,8 @@ pub enum SetErrorType {
AddressBookHasContents,
#[serde(rename = "nodeHasChildren")]
NodeHasChildren,
#[serde(rename = "calendarHasEvent")]
CalendarHasEvent,
}
impl SetErrorType {
@@ -119,6 +121,7 @@ impl SetErrorType {
SetErrorType::ScriptIsActive => "scriptIsActive",
SetErrorType::AddressBookHasContents => "addressBookHasContents",
SetErrorType::NodeHasChildren => "nodeHasChildren",
SetErrorType::CalendarHasEvent => "calendarHasEvent",
}
}
}
@@ -200,6 +203,10 @@ impl<T: Property> SetError<T> {
pub fn node_has_children() -> Self {
Self::new(SetErrorType::NodeHasChildren).with_description("File node has children.")
}
pub fn calendar_has_event() -> Self {
Self::new(SetErrorType::CalendarHasEvent).with_description("Calendar is not empty.")
}
}
impl<T: Property> From<T> for InvalidProperty<T> {

View File

@@ -13,7 +13,7 @@ use crate::{
};
use calcard::jscalendar::{JSCalendar, JSCalendarProperty};
use serde::{Deserialize, Deserializer, Serialize};
use types::id::Id;
use types::{blob::BlobId, id::Id};
#[derive(Debug, Clone, Default)]
pub struct GetAvailabilityRequest {
@@ -37,7 +37,7 @@ pub struct BusyPeriod {
pub utc_start: UTCDate,
pub utc_end: UTCDate,
pub busy_status: Option<BusyStatus>,
pub event: Option<JSCalendar<'static, Id>>,
pub event: Option<JSCalendar<'static, Id, BlobId>>,
}
#[derive(Debug, Serialize, Clone)]

View File

@@ -15,7 +15,7 @@ use calcard::{
};
use jmap_tools::{JsonPointerItem, Key};
use std::{borrow::Cow, str::FromStr};
use types::id::Id;
use types::{blob::BlobId, id::Id};
#[derive(Debug, Clone, Default)]
pub struct CalendarEvent;
@@ -23,7 +23,7 @@ pub struct CalendarEvent;
impl JmapObject for CalendarEvent {
type Property = JSCalendarProperty<Id>;
type Element = JSCalendarValue<Id>;
type Element = JSCalendarValue<Id, BlobId>;
type Id = Id;
@@ -44,7 +44,7 @@ impl JmapObject for CalendarEvent {
const ID_PROPERTY: Self::Property = JSCalendarProperty::Id;
}
impl JmapObjectId for JSCalendarValue<Id> {
impl JmapObjectId for JSCalendarValue<Id, BlobId> {
fn as_id(&self) -> Option<Id> {
if let JSCalendarValue::Id(id) = self {
Some(*id)
@@ -54,10 +54,10 @@ impl JmapObjectId for JSCalendarValue<Id> {
}
fn as_any_id(&self) -> Option<AnyId> {
if let JSCalendarValue::Id(id) = self {
Some(AnyId::Id(*id))
} else {
None
match self {
JSCalendarValue::Id(id) => Some(AnyId::Id(*id)),
JSCalendarValue::BlobId(blob_id) => Some(AnyId::BlobId(blob_id.clone())),
_ => None,
}
}

View File

@@ -13,7 +13,7 @@ use calcard::jscalendar::JSCalendar;
use jmap_tools::{Element, Key, Property};
use serde::Serialize;
use std::{borrow::Cow, str::FromStr};
use types::id::Id;
use types::{blob::BlobId, id::Id};
#[derive(Debug, Clone, Default)]
pub struct CalendarEventNotification;
@@ -43,10 +43,10 @@ pub struct CalendarEventNotificationObject {
pub is_draft: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub event: Option<JSCalendar<'static, Id>>,
pub event: Option<JSCalendar<'static, Id, BlobId>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub event_patch: Option<JSCalendar<'static, Id>>,
pub event_patch: Option<JSCalendar<'static, Id, BlobId>>,
}
#[derive(Debug, Serialize, Clone)]