use jmap_types::{Id, State};
use super::{ChangesResponse, GetResponse, QueryChangesResponse, QueryResponse, SetResponse};
impl super::SessionClient {
pub async fn task_notification_get(
&self,
ids: Option<&[Id]>,
properties: Option<&[&str]>,
) -> Result<GetResponse<jmap_tasks_types::TaskNotification>, jmap_base_client::ClientError>
{
let (api_url, account_id) = self.session_parts()?;
let mut args = serde_json::json!({ "accountId": account_id });
if let Some(id_slice) = ids {
args["ids"] = serde_json::to_value(id_slice).expect("Id slice Serialize is infallible");
}
if let Some(props) = properties {
args["properties"] =
serde_json::to_value(props).expect("&[&str] Serialize is infallible");
}
let req = super::build_request("TaskNotification/get", args, super::USING_TASKS);
let resp = self.call_internal(api_url, &req).await?;
jmap_base_client::extract_response(&resp, super::CALL_ID)
}
pub async fn task_notification_changes(
&self,
since_state: &State,
max_changes: Option<u64>,
) -> Result<ChangesResponse, jmap_base_client::ClientError> {
if since_state.as_ref().is_empty() {
return Err(jmap_base_client::ClientError::InvalidArgument(
"task_notification_changes: since_state may not be empty".into(),
));
}
let (api_url, account_id) = self.session_parts()?;
let mut args = serde_json::json!({
"accountId": account_id,
"sinceState": since_state,
});
if let Some(mc) = max_changes {
args["maxChanges"] = mc.into();
}
let req = super::build_request("TaskNotification/changes", args, super::USING_TASKS);
let resp = self.call_internal(api_url, &req).await?;
jmap_base_client::extract_response(&resp, super::CALL_ID)
}
pub async fn task_notification_set(
&self,
destroy: Vec<Id>,
) -> Result<SetResponse, jmap_base_client::ClientError> {
let (api_url, account_id) = self.session_parts()?;
let args = serde_json::json!({
"accountId": account_id,
"destroy": destroy,
});
let req = super::build_request("TaskNotification/set", args, super::USING_TASKS);
let resp = self.call_internal(api_url, &req).await?;
jmap_base_client::extract_response(&resp, super::CALL_ID)
}
pub async fn task_notification_query(
&self,
filter: Option<serde_json::Value>,
sort: Option<serde_json::Value>,
position: Option<u64>,
limit: Option<u64>,
) -> Result<QueryResponse, jmap_base_client::ClientError> {
let (api_url, account_id) = self.session_parts()?;
let mut args = serde_json::json!({
"accountId": account_id,
});
if let Some(f) = filter {
args["filter"] = f;
}
if let Some(s) = sort {
args["sort"] = s;
}
if let Some(p) = position {
args["position"] = p.into();
}
if let Some(l) = limit {
args["limit"] = l.into();
}
let req = super::build_request("TaskNotification/query", args, super::USING_TASKS);
let resp = self.call_internal(api_url, &req).await?;
jmap_base_client::extract_response(&resp, super::CALL_ID)
}
pub async fn task_notification_query_changes(
&self,
since_query_state: &State,
max_changes: Option<u64>,
filter: Option<serde_json::Value>,
sort: Option<serde_json::Value>,
up_to_id: Option<&Id>,
calculate_total: Option<bool>,
) -> Result<QueryChangesResponse, jmap_base_client::ClientError> {
if since_query_state.as_ref().is_empty() {
return Err(jmap_base_client::ClientError::InvalidArgument(
"task_notification_query_changes: since_query_state may not be empty".into(),
));
}
let (api_url, account_id) = self.session_parts()?;
let mut args = serde_json::json!({
"accountId": account_id,
"sinceQueryState": since_query_state,
});
if let Some(f) = filter {
args["filter"] = f;
}
if let Some(s) = sort {
args["sort"] = s;
}
if let Some(mc) = max_changes {
args["maxChanges"] = mc.into();
}
if let Some(uti) = up_to_id {
args["upToId"] = serde_json::to_value(uti).expect("Id Serialize is infallible");
}
if let Some(ct) = calculate_total {
args["calculateTotal"] = ct.into();
}
let req = super::build_request("TaskNotification/queryChanges", args, super::USING_TASKS);
let resp = self.call_internal(api_url, &req).await?;
jmap_base_client::extract_response(&resp, super::CALL_ID)
}
}