JMAP protocol layer refactoring (part 4) (fixes #1507)

This commit is contained in:
mdecimus
2025-09-26 17:01:26 +02:00
parent efa83c2255
commit 8c67abcd3c
26 changed files with 1983 additions and 925 deletions

View File

@@ -5,6 +5,7 @@
*/
use crate::{
method::PropertyWrapper,
object::JmapObject,
request::deserialize::{DeserializeArguments, deserialize_request},
types::state::State,
@@ -41,7 +42,7 @@ pub struct ChangesResponse<T: JmapObject> {
#[serde(rename = "updatedProperties")]
#[serde(skip_serializing_if = "Option::is_none")]
pub updated_properties: Option<Vec<T::Property>>,
pub updated_properties: Option<Vec<PropertyWrapper<T::Property>>>,
}
impl<'de> DeserializeArguments<'de> for ChangesRequest {

View File

@@ -6,7 +6,10 @@
use crate::{
error::set::SetError,
object::email::{EmailProperty, EmailValue},
object::{
AnyId,
email::{EmailProperty, EmailValue},
},
request::{
MaybeInvalid,
deserialize::{DeserializeArguments, deserialize_request},
@@ -135,7 +138,7 @@ impl ImportEmailResponse {
&& let Some(Value::Element(EmailValue::Id(id))) =
obj.get(&Key::Property(EmailProperty::Id))
{
response.created_ids.insert(user_id.clone(), (*id).into());
response.created_ids.insert(user_id.clone(), AnyId::Id(*id));
}
}
}

View File

@@ -5,6 +5,7 @@
*/
use ahash::AHashMap;
use jmap_tools::Property;
pub mod changes;
pub mod copy;
@@ -23,3 +24,16 @@ pub mod validate;
fn ahash_is_empty<K, V>(map: &AHashMap<K, V>) -> bool {
map.is_empty()
}
#[derive(Debug, Clone, serde::Serialize)]
#[serde(transparent)]
#[repr(transparent)]
pub struct PropertyWrapper<T>(pub T)
where
T: serde::Serialize + Property;
impl<T: Property + serde::Serialize> From<T> for PropertyWrapper<T> {
fn from(value: T) -> Self {
Self(value)
}
}

View File

@@ -7,7 +7,7 @@
use super::ahash_is_empty;
use crate::{
error::set::{InvalidProperty, SetError},
object::JmapObject,
object::{JmapObject, JmapObjectId},
request::{
MaybeInvalid,
deserialize::{DeserializeArguments, deserialize_request},
@@ -250,9 +250,10 @@ impl<T: JmapObject> SetResponse<T> {
pub fn update_created_ids(&self, response: &mut Response) {
for (user_id, obj) in &self.created {
if let Value::Object(obj) = obj
&& let Some(id) = obj.get(&Key::Property(T::ID_PROPERTY))
&& let Some(Value::Element(id)) = obj.get(&Key::Property(T::ID_PROPERTY))
&& let Some(id) = id.as_any_id()
{
response.created_ids.insert(user_id.clone(), id.to_string());
response.created_ids.insert(user_id.clone(), id);
}
}
}

View File

@@ -9,7 +9,7 @@ use std::borrow::Cow;
use super::ahash_is_empty;
use crate::{
error::set::SetError,
object::blob::BlobProperty,
object::{AnyId, blob::BlobProperty},
request::{
deserialize::{DeserializeArguments, deserialize_request},
reference::MaybeIdReference,
@@ -179,7 +179,7 @@ impl BlobUploadResponse {
for (user_id, obj) in &self.created {
response
.created_ids
.insert(user_id.clone(), obj.id.to_string());
.insert(user_id.clone(), AnyId::BlobId(obj.id.clone()));
}
}
}