jmap_tasks_client/methods/
task_notification.rs1use jmap_types::{Id, State};
8
9use super::{ChangesResponse, GetResponse, QueryChangesResponse, QueryResponse, SetResponse};
10
11impl super::SessionClient {
12 pub async fn task_notification_get(
16 &self,
17 ids: Option<&[Id]>,
18 properties: Option<&[&str]>,
19 ) -> Result<GetResponse<jmap_tasks_types::TaskNotification>, jmap_base_client::ClientError>
20 {
21 let (api_url, account_id) = self.session_parts()?;
22 let mut args = serde_json::json!({ "accountId": account_id });
25 if let Some(id_slice) = ids {
26 args["ids"] = serde_json::to_value(id_slice).expect("Id slice Serialize is infallible");
27 }
28 if let Some(props) = properties {
29 args["properties"] = serde_json::Value::Array(
30 props.iter().copied().map(serde_json::Value::from).collect(),
31 );
32 }
33 let req = super::build_request("TaskNotification/get", args, super::USING_TASKS);
34 let resp = self.call_internal(api_url, &req).await?;
35 jmap_base_client::extract_response(&resp, super::CALL_ID)
36 }
37
38 pub async fn task_notification_changes(
41 &self,
42 since_state: &State,
43 max_changes: Option<u64>,
44 ) -> Result<ChangesResponse, jmap_base_client::ClientError> {
45 if since_state.as_ref().is_empty() {
47 return Err(jmap_base_client::ClientError::InvalidArgument(
48 "task_notification_changes: since_state may not be empty".into(),
49 ));
50 }
51 let (api_url, account_id) = self.session_parts()?;
52 let mut args = serde_json::json!({
53 "accountId": account_id,
54 "sinceState": since_state,
55 });
56 if let Some(mc) = max_changes {
57 args["maxChanges"] = mc.into();
58 }
59 let req = super::build_request("TaskNotification/changes", args, super::USING_TASKS);
60 let resp = self.call_internal(api_url, &req).await?;
61 jmap_base_client::extract_response(&resp, super::CALL_ID)
62 }
63
64 pub async fn task_notification_set(
71 &self,
72 destroy: Vec<Id>,
73 ) -> Result<SetResponse, jmap_base_client::ClientError> {
74 let (api_url, account_id) = self.session_parts()?;
75 let args = serde_json::json!({
76 "accountId": account_id,
77 "destroy": destroy,
78 });
79 let req = super::build_request("TaskNotification/set", args, super::USING_TASKS);
80 let resp = self.call_internal(api_url, &req).await?;
81 jmap_base_client::extract_response(&resp, super::CALL_ID)
82 }
83
84 pub async fn task_notification_query(
87 &self,
88 filter: Option<serde_json::Value>,
89 sort: Option<serde_json::Value>,
90 position: Option<u64>,
91 limit: Option<u64>,
92 ) -> Result<QueryResponse, jmap_base_client::ClientError> {
93 let (api_url, account_id) = self.session_parts()?;
94 let mut args = serde_json::json!({
95 "accountId": account_id,
96 });
97 if let Some(f) = filter {
98 args["filter"] = f;
99 }
100 if let Some(s) = sort {
101 args["sort"] = s;
102 }
103 if let Some(p) = position {
104 args["position"] = p.into();
105 }
106 if let Some(l) = limit {
107 args["limit"] = l.into();
108 }
109 let req = super::build_request("TaskNotification/query", args, super::USING_TASKS);
110 let resp = self.call_internal(api_url, &req).await?;
111 jmap_base_client::extract_response(&resp, super::CALL_ID)
112 }
113
114 pub async fn task_notification_query_changes(
117 &self,
118 since_query_state: &State,
119 max_changes: Option<u64>,
120 ) -> Result<QueryChangesResponse, jmap_base_client::ClientError> {
121 if since_query_state.as_ref().is_empty() {
123 return Err(jmap_base_client::ClientError::InvalidArgument(
124 "task_notification_query_changes: since_query_state may not be empty".into(),
125 ));
126 }
127 let (api_url, account_id) = self.session_parts()?;
128 let mut args = serde_json::json!({
129 "accountId": account_id,
130 "sinceQueryState": since_query_state,
131 });
132 if let Some(mc) = max_changes {
133 args["maxChanges"] = mc.into();
134 }
135 let req = super::build_request("TaskNotification/queryChanges", args, super::USING_TASKS);
136 let resp = self.call_internal(api_url, &req).await?;
137 jmap_base_client::extract_response(&resp, super::CALL_ID)
138 }
139}
140
141