mattermost_rust_client/apis/
status_api.rs

1/*
2 * Mattermost API Reference
3 *
4 * There is also a work-in-progress [Postman API reference](https://documenter.getpostman.com/view/4508214/RW8FERUn). 
5 *
6 * The version of the OpenAPI document: 4.0.0
7 * Contact: feedback@mattermost.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`get_user_status`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetUserStatusError {
22    Status400(crate::models::AppError),
23    Status401(crate::models::AppError),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`get_users_statuses_by_ids`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum GetUsersStatusesByIdsError {
31    Status400(crate::models::AppError),
32    Status401(crate::models::AppError),
33    UnknownValue(serde_json::Value),
34}
35
36/// struct for typed errors of method [`post_user_recent_custom_status_delete`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum PostUserRecentCustomStatusDeleteError {
40    Status400(crate::models::AppError),
41    Status401(crate::models::AppError),
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`remove_recent_custom_status`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum RemoveRecentCustomStatusError {
49    Status400(crate::models::AppError),
50    Status401(crate::models::AppError),
51    UnknownValue(serde_json::Value),
52}
53
54/// struct for typed errors of method [`unset_user_custom_status`]
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum UnsetUserCustomStatusError {
58    Status400(crate::models::AppError),
59    Status401(crate::models::AppError),
60    UnknownValue(serde_json::Value),
61}
62
63/// struct for typed errors of method [`update_user_custom_status`]
64#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(untagged)]
66pub enum UpdateUserCustomStatusError {
67    Status400(crate::models::AppError),
68    Status401(crate::models::AppError),
69    UnknownValue(serde_json::Value),
70}
71
72/// struct for typed errors of method [`update_user_status`]
73#[derive(Debug, Clone, Serialize, Deserialize)]
74#[serde(untagged)]
75pub enum UpdateUserStatusError {
76    Status400(crate::models::AppError),
77    Status401(crate::models::AppError),
78    UnknownValue(serde_json::Value),
79}
80
81
82/// Get user status by id from the server. ##### Permissions Must be authenticated. 
83pub async fn get_user_status(configuration: &configuration::Configuration, user_id: &str) -> Result<crate::models::Status, Error<GetUserStatusError>> {
84    let local_var_configuration = configuration;
85
86    let local_var_client = &local_var_configuration.client;
87
88    let local_var_uri_str = format!("{}/users/{user_id}/status", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id));
89    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
90
91    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
92        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
93    }
94    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
95        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
96    };
97
98    let local_var_req = local_var_req_builder.build()?;
99    let local_var_resp = local_var_client.execute(local_var_req).await?;
100
101    let local_var_status = local_var_resp.status();
102    let local_var_content = local_var_resp.text().await?;
103
104    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
105        serde_json::from_str(&local_var_content).map_err(Error::from)
106    } else {
107        let local_var_entity: Option<GetUserStatusError> = serde_json::from_str(&local_var_content).ok();
108        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
109        Err(Error::ResponseError(local_var_error))
110    }
111}
112
113/// Get a list of user statuses by id from the server. ##### Permissions Must be authenticated. 
114pub async fn get_users_statuses_by_ids(configuration: &configuration::Configuration, request_body: Vec<String>) -> Result<Vec<crate::models::Status>, Error<GetUsersStatusesByIdsError>> {
115    let local_var_configuration = configuration;
116
117    let local_var_client = &local_var_configuration.client;
118
119    let local_var_uri_str = format!("{}/users/status/ids", local_var_configuration.base_path);
120    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
121
122    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
123        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
124    }
125    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
126        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
127    };
128    local_var_req_builder = local_var_req_builder.json(&request_body);
129
130    let local_var_req = local_var_req_builder.build()?;
131    let local_var_resp = local_var_client.execute(local_var_req).await?;
132
133    let local_var_status = local_var_resp.status();
134    let local_var_content = local_var_resp.text().await?;
135
136    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
137        serde_json::from_str(&local_var_content).map_err(Error::from)
138    } else {
139        let local_var_entity: Option<GetUsersStatusesByIdsError> = serde_json::from_str(&local_var_content).ok();
140        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
141        Err(Error::ResponseError(local_var_error))
142    }
143}
144
145/// Deletes a user's recent custom status by removing the specific status from the recentCustomStatuses in the user's props and updates the user. ##### Permissions Must be logged in as the user whose recent custom status is being deleted. 
146pub async fn post_user_recent_custom_status_delete(configuration: &configuration::Configuration, user_id: &str, remove_recent_custom_status_request: crate::models::RemoveRecentCustomStatusRequest) -> Result<(), Error<PostUserRecentCustomStatusDeleteError>> {
147    let local_var_configuration = configuration;
148
149    let local_var_client = &local_var_configuration.client;
150
151    let local_var_uri_str = format!("{}/users/{user_id}/status/custom/recent/delete", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id));
152    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
153
154    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
155        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
156    }
157    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
158        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
159    };
160    local_var_req_builder = local_var_req_builder.json(&remove_recent_custom_status_request);
161
162    let local_var_req = local_var_req_builder.build()?;
163    let local_var_resp = local_var_client.execute(local_var_req).await?;
164
165    let local_var_status = local_var_resp.status();
166    let local_var_content = local_var_resp.text().await?;
167
168    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
169        Ok(())
170    } else {
171        let local_var_entity: Option<PostUserRecentCustomStatusDeleteError> = serde_json::from_str(&local_var_content).ok();
172        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
173        Err(Error::ResponseError(local_var_error))
174    }
175}
176
177/// Deletes a user's recent custom status by removing the specific status from the recentCustomStatuses in the user's props and updates the user. ##### Permissions Must be logged in as the user whose recent custom status is being deleted. 
178pub async fn remove_recent_custom_status(configuration: &configuration::Configuration, user_id: &str, remove_recent_custom_status_request: crate::models::RemoveRecentCustomStatusRequest) -> Result<(), Error<RemoveRecentCustomStatusError>> {
179    let local_var_configuration = configuration;
180
181    let local_var_client = &local_var_configuration.client;
182
183    let local_var_uri_str = format!("{}/users/{user_id}/status/custom/recent", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id));
184    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
185
186    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
187        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
188    }
189    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
190        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
191    };
192    local_var_req_builder = local_var_req_builder.json(&remove_recent_custom_status_request);
193
194    let local_var_req = local_var_req_builder.build()?;
195    let local_var_resp = local_var_client.execute(local_var_req).await?;
196
197    let local_var_status = local_var_resp.status();
198    let local_var_content = local_var_resp.text().await?;
199
200    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
201        Ok(())
202    } else {
203        let local_var_entity: Option<RemoveRecentCustomStatusError> = serde_json::from_str(&local_var_content).ok();
204        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
205        Err(Error::ResponseError(local_var_error))
206    }
207}
208
209/// Unsets a user's custom status by updating the user's props and updates the user ##### Permissions Must be logged in as the user whose custom status is being removed. 
210pub async fn unset_user_custom_status(configuration: &configuration::Configuration, user_id: &str) -> Result<(), Error<UnsetUserCustomStatusError>> {
211    let local_var_configuration = configuration;
212
213    let local_var_client = &local_var_configuration.client;
214
215    let local_var_uri_str = format!("{}/users/{user_id}/status/custom", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id));
216    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
217
218    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
219        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
220    }
221    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
222        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
223    };
224
225    let local_var_req = local_var_req_builder.build()?;
226    let local_var_resp = local_var_client.execute(local_var_req).await?;
227
228    let local_var_status = local_var_resp.status();
229    let local_var_content = local_var_resp.text().await?;
230
231    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
232        Ok(())
233    } else {
234        let local_var_entity: Option<UnsetUserCustomStatusError> = serde_json::from_str(&local_var_content).ok();
235        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
236        Err(Error::ResponseError(local_var_error))
237    }
238}
239
240/// Updates a user's custom status by setting the value in the user's props and updates the user. Also save the given custom status to the recent custom statuses in the user's props ##### Permissions Must be logged in as the user whose custom status is being updated. 
241pub async fn update_user_custom_status(configuration: &configuration::Configuration, user_id: &str, update_user_custom_status_request: crate::models::UpdateUserCustomStatusRequest) -> Result<(), Error<UpdateUserCustomStatusError>> {
242    let local_var_configuration = configuration;
243
244    let local_var_client = &local_var_configuration.client;
245
246    let local_var_uri_str = format!("{}/users/{user_id}/status/custom", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id));
247    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
248
249    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
250        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
251    }
252    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
253        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
254    };
255    local_var_req_builder = local_var_req_builder.json(&update_user_custom_status_request);
256
257    let local_var_req = local_var_req_builder.build()?;
258    let local_var_resp = local_var_client.execute(local_var_req).await?;
259
260    let local_var_status = local_var_resp.status();
261    let local_var_content = local_var_resp.text().await?;
262
263    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
264        Ok(())
265    } else {
266        let local_var_entity: Option<UpdateUserCustomStatusError> = serde_json::from_str(&local_var_content).ok();
267        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
268        Err(Error::ResponseError(local_var_error))
269    }
270}
271
272/// Manually set a user's status. When setting a user's status, the status will remain that value until set \"online\" again, which will return the status to being automatically updated based on user activity. ##### Permissions Must have `edit_other_users` permission for the team. 
273pub async fn update_user_status(configuration: &configuration::Configuration, user_id: &str, update_user_status_request: crate::models::UpdateUserStatusRequest) -> Result<crate::models::Status, Error<UpdateUserStatusError>> {
274    let local_var_configuration = configuration;
275
276    let local_var_client = &local_var_configuration.client;
277
278    let local_var_uri_str = format!("{}/users/{user_id}/status", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id));
279    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
280
281    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
282        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
283    }
284    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
285        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
286    };
287    local_var_req_builder = local_var_req_builder.json(&update_user_status_request);
288
289    let local_var_req = local_var_req_builder.build()?;
290    let local_var_resp = local_var_client.execute(local_var_req).await?;
291
292    let local_var_status = local_var_resp.status();
293    let local_var_content = local_var_resp.text().await?;
294
295    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
296        serde_json::from_str(&local_var_content).map_err(Error::from)
297    } else {
298        let local_var_entity: Option<UpdateUserStatusError> = serde_json::from_str(&local_var_content).ok();
299        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
300        Err(Error::ResponseError(local_var_error))
301    }
302}
303