Reference support in ChangesRequest.

main
Mauro D 2022-08-24 13:47:22 +00:00
parent 29ec39d98c
commit 47cad8fd17
4 changed files with 39 additions and 6 deletions

View File

@ -112,6 +112,7 @@ impl ClientBuilder {
let trusted_hosts = Arc::new(self.trusted_hosts);
let trusted_hosts_ = trusted_hosts.clone();
let session_url = format!("{}/.well-known/jmap", url);
let session: Session = serde_json::from_slice(
&Client::handle_error(
reqwest::Client::builder()
@ -132,7 +133,7 @@ impl ClientBuilder {
}))
.default_headers(headers.clone())
.build()?
.get(url)
.get(&session_url)
.send()
.await?,
)
@ -159,7 +160,7 @@ impl ClientBuilder {
event_source_url: URLPart::parse(session.event_source_url())?,
api_url: session.api_url().to_string(),
session: parking_lot::Mutex::new(Arc::new(session)),
session_url: url.to_string(),
session_url,
session_updated: true.into(),
trusted_hosts,
#[cfg(feature = "websockets")]
@ -191,6 +192,7 @@ impl ClientBuilder {
let trusted_hosts = Arc::new(self.trusted_hosts);
let trusted_hosts_ = trusted_hosts.clone();
let session_url = format!("{}/.well-known/jmap", url);
let session: Session = serde_json::from_slice(
&Client::handle_error(
reqwest::blocking::Client::builder()
@ -211,7 +213,7 @@ impl ClientBuilder {
}))
.default_headers(headers.clone())
.build()?
.get(url)
.get(&session_url)
.send()
?,
)?
@ -236,7 +238,7 @@ impl ClientBuilder {
event_source_url: URLPart::parse(session.event_source_url())?,
api_url: session.api_url().to_string(),
session: parking_lot::Mutex::new(Arc::new(session)),
session_url: url.to_string(),
session_url,
session_updated: true.into(),
trusted_hosts,
#[cfg(feature = "websockets")]

View File

@ -1,6 +1,8 @@
use serde::{Deserialize, Serialize};
use super::{Object, RequestParams};
use crate::Method;
use super::{request::ResultReference, Object, RequestParams};
pub trait ChangesObject: Object {
type ChangesResponse;
@ -8,6 +10,9 @@ pub trait ChangesObject: Object {
#[derive(Debug, Clone, Serialize)]
pub struct ChangesRequest {
#[serde(skip)]
method: (Method, usize),
#[serde(rename = "accountId")]
account_id: String,
@ -46,6 +51,7 @@ pub struct ChangesResponse<O: ChangesObject> {
impl ChangesRequest {
pub fn new(params: RequestParams, since_state: String) -> Self {
ChangesRequest {
method: (params.method, params.call_id),
account_id: params.account_id,
since_state,
max_changes: None,
@ -61,6 +67,18 @@ impl ChangesRequest {
self.max_changes = Some(max_changes);
self
}
pub fn created_reference(&self) -> ResultReference {
ResultReference::new(self.method.0, self.method.1, "/created")
}
pub fn updated_reference(&self) -> ResultReference {
ResultReference::new(self.method.0, self.method.1, "/updated")
}
pub fn updated_properties_reference(&self) -> ResultReference {
ResultReference::new(self.method.0, self.method.1, "/updatedProperties")
}
}
impl<O: ChangesObject> ChangesResponse<O> {

View File

@ -28,6 +28,11 @@ pub struct GetRequest<O: GetObject> {
#[serde(skip_serializing_if = "Option::is_none")]
properties: Option<Vec<O::Property>>,
#[serde(rename = "#properties")]
#[serde(skip_deserializing)]
#[serde(skip_serializing_if = "Option::is_none")]
properties_ref: Option<ResultReference>,
#[serde(flatten)]
arguments: O::GetArguments,
}
@ -57,6 +62,7 @@ impl<O: GetObject> GetRequest<O> {
ids: None,
ids_ref: None,
properties: None,
properties_ref: None,
arguments: O::GetArguments::default(),
}
}
@ -86,6 +92,13 @@ impl<O: GetObject> GetRequest<O> {
pub fn properties(&mut self, properties: impl IntoIterator<Item = O::Property>) -> &mut Self {
self.properties = Some(properties.into_iter().collect());
self.properties_ref = None;
self
}
pub fn properties_ref(&mut self, reference: ResultReference) -> &mut Self {
self.properties_ref = Some(reference);
self.properties = None;
self
}

View File

@ -131,7 +131,7 @@ impl Default for Role {
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct MailboxRights {
#[serde(rename = "mayReadItems")]
may_read_items: bool,