jmap_chat_client/methods/
space_invite.rs1use jmap_types::{Id, State};
6
7use super::{ChangesResponse, GetResponse, SetResponse, SpaceInviteCreateInput};
8
9impl super::SessionClient {
10 pub async fn space_invite_get(
15 &self,
16 ids: Option<&[Id]>,
17 properties: Option<&[&str]>,
18 ) -> Result<GetResponse<jmap_chat_types::SpaceInvite>, jmap_base_client::ClientError> {
19 let (api_url, account_id) = self.session_parts()?;
20 let mut args = serde_json::json!({ "accountId": account_id });
23 if let Some(id_slice) = ids {
24 args["ids"] = serde_json::to_value(id_slice).expect("Id slice Serialize is infallible");
25 }
26 if let Some(props) = properties {
27 args["properties"] = serde_json::Value::Array(
28 props.iter().copied().map(serde_json::Value::from).collect(),
29 );
30 }
31 let req = super::build_request("SpaceInvite/get", args, super::USING_CHAT);
32 let resp = self.call_internal(api_url, &req).await?;
33 jmap_base_client::extract_response(&resp, super::CALL_ID)
34 }
35
36 pub async fn space_invite_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 "space_invite_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("SpaceInvite/changes", args, super::USING_CHAT);
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 space_invite_create(
68 &self,
69 input: &SpaceInviteCreateInput<'_>,
70 ) -> Result<SetResponse, jmap_base_client::ClientError> {
71 let (api_url, account_id) = self.session_parts()?;
72 let mut obj = serde_json::json!({ "spaceId": input.space_id });
73 if let Some(ch) = input.default_channel_id {
74 obj["defaultChannelId"] = ch.as_ref().into();
75 }
76 if let Some(ea) = input.expires_at {
77 obj["expiresAt"] = ea.as_ref().into();
78 }
79 if let Some(mu) = input.max_uses {
80 obj["maxUses"] = mu.into();
81 }
82 let client_id = super::resolve_client_id(input.client_id);
83 let args = serde_json::json!({
84 "accountId": account_id,
85 "create": { client_id: obj },
86 });
87 let req = super::build_request("SpaceInvite/set", args, super::USING_CHAT);
88 let resp = self.call_internal(api_url, &req).await?;
89 jmap_base_client::extract_response(&resp, super::CALL_ID)
90 }
91
92 pub async fn space_invite_destroy(
96 &self,
97 ids: &[Id],
98 ) -> Result<SetResponse, jmap_base_client::ClientError> {
99 if ids.is_empty() {
100 return Err(jmap_base_client::ClientError::InvalidArgument(
101 "space_invite_destroy: ids may not be empty".into(),
102 ));
103 }
104 let (api_url, account_id) = self.session_parts()?;
105 let args = serde_json::json!({
106 "accountId": account_id,
107 "destroy": ids,
108 });
109 let req = super::build_request("SpaceInvite/set", args, super::USING_CHAT);
110 let resp = self.call_internal(api_url, &req).await?;
111 jmap_base_client::extract_response(&resp, super::CALL_ID)
112 }
113}