mattermost_rust_client/apis/
threads_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_thread_mention_counts_by_channel`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetThreadMentionCountsByChannelError {
22    Status400(crate::models::AppError),
23    Status401(crate::models::AppError),
24    Status404(crate::models::AppError),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`get_user_thread`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum GetUserThreadError {
32    Status400(crate::models::AppError),
33    Status401(crate::models::AppError),
34    Status404(crate::models::AppError),
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`get_user_threads`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum GetUserThreadsError {
42    Status400(crate::models::AppError),
43    Status401(crate::models::AppError),
44    Status404(crate::models::AppError),
45    UnknownValue(serde_json::Value),
46}
47
48/// struct for typed errors of method [`set_thread_unread_by_post_id`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum SetThreadUnreadByPostIdError {
52    Status400(crate::models::AppError),
53    Status401(crate::models::AppError),
54    Status404(crate::models::AppError),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`start_following_thread`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum StartFollowingThreadError {
62    Status400(crate::models::AppError),
63    Status401(crate::models::AppError),
64    Status404(crate::models::AppError),
65    UnknownValue(serde_json::Value),
66}
67
68/// struct for typed errors of method [`stop_following_thread`]
69#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum StopFollowingThreadError {
72    Status400(crate::models::AppError),
73    Status401(crate::models::AppError),
74    Status404(crate::models::AppError),
75    UnknownValue(serde_json::Value),
76}
77
78/// struct for typed errors of method [`update_thread_read_for_user`]
79#[derive(Debug, Clone, Serialize, Deserialize)]
80#[serde(untagged)]
81pub enum UpdateThreadReadForUserError {
82    Status400(crate::models::AppError),
83    Status401(crate::models::AppError),
84    Status404(crate::models::AppError),
85    UnknownValue(serde_json::Value),
86}
87
88/// struct for typed errors of method [`update_threads_read_for_user`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum UpdateThreadsReadForUserError {
92    Status400(crate::models::AppError),
93    Status401(crate::models::AppError),
94    Status404(crate::models::AppError),
95    UnknownValue(serde_json::Value),
96}
97
98
99/// Get all unread mention counts from followed threads  __Minimum server version__: 5.29  ##### Permissions Must be logged in as the user or have `edit_other_users` permission. 
100pub async fn get_thread_mention_counts_by_channel(configuration: &configuration::Configuration, user_id: &str, team_id: &str) -> Result<(), Error<GetThreadMentionCountsByChannelError>> {
101    let local_var_configuration = configuration;
102
103    let local_var_client = &local_var_configuration.client;
104
105    let local_var_uri_str = format!("{}/users/{user_id}/teams/{team_id}/threads/mention_counts", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id), team_id=crate::apis::urlencode(team_id));
106    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
107
108    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
109        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
110    }
111    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
112        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
113    };
114
115    let local_var_req = local_var_req_builder.build()?;
116    let local_var_resp = local_var_client.execute(local_var_req).await?;
117
118    let local_var_status = local_var_resp.status();
119    let local_var_content = local_var_resp.text().await?;
120
121    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
122        Ok(())
123    } else {
124        let local_var_entity: Option<GetThreadMentionCountsByChannelError> = serde_json::from_str(&local_var_content).ok();
125        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
126        Err(Error::ResponseError(local_var_error))
127    }
128}
129
130/// Get a thread  __Minimum server version__: 5.29  ##### Permissions Must be logged in as the user or have `edit_other_users` permission. 
131pub async fn get_user_thread(configuration: &configuration::Configuration, user_id: &str, team_id: &str, thread_id: &str) -> Result<(), Error<GetUserThreadError>> {
132    let local_var_configuration = configuration;
133
134    let local_var_client = &local_var_configuration.client;
135
136    let local_var_uri_str = format!("{}/users/{user_id}/teams/{team_id}/threads/{thread_id}", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id), team_id=crate::apis::urlencode(team_id), thread_id=crate::apis::urlencode(thread_id));
137    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
138
139    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
140        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
141    }
142    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
143        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
144    };
145
146    let local_var_req = local_var_req_builder.build()?;
147    let local_var_resp = local_var_client.execute(local_var_req).await?;
148
149    let local_var_status = local_var_resp.status();
150    let local_var_content = local_var_resp.text().await?;
151
152    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
153        Ok(())
154    } else {
155        let local_var_entity: Option<GetUserThreadError> = serde_json::from_str(&local_var_content).ok();
156        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
157        Err(Error::ResponseError(local_var_error))
158    }
159}
160
161/// Get all threads that user is following  __Minimum server version__: 5.29  ##### Permissions Must be logged in as the user or have `edit_other_users` permission. 
162pub async fn get_user_threads(configuration: &configuration::Configuration, user_id: &str, team_id: &str, since: Option<i32>, deleted: Option<bool>, extended: Option<bool>, page: Option<i32>, page_size: Option<i32>, totals_only: Option<bool>, threads_only: Option<bool>) -> Result<crate::models::UserThreads, Error<GetUserThreadsError>> {
163    let local_var_configuration = configuration;
164
165    let local_var_client = &local_var_configuration.client;
166
167    let local_var_uri_str = format!("{}/users/{user_id}/teams/{team_id}/threads", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id), team_id=crate::apis::urlencode(team_id));
168    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
169
170    if let Some(ref local_var_str) = since {
171        local_var_req_builder = local_var_req_builder.query(&[("since", &local_var_str.to_string())]);
172    }
173    if let Some(ref local_var_str) = deleted {
174        local_var_req_builder = local_var_req_builder.query(&[("deleted", &local_var_str.to_string())]);
175    }
176    if let Some(ref local_var_str) = extended {
177        local_var_req_builder = local_var_req_builder.query(&[("extended", &local_var_str.to_string())]);
178    }
179    if let Some(ref local_var_str) = page {
180        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
181    }
182    if let Some(ref local_var_str) = page_size {
183        local_var_req_builder = local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
184    }
185    if let Some(ref local_var_str) = totals_only {
186        local_var_req_builder = local_var_req_builder.query(&[("totalsOnly", &local_var_str.to_string())]);
187    }
188    if let Some(ref local_var_str) = threads_only {
189        local_var_req_builder = local_var_req_builder.query(&[("threadsOnly", &local_var_str.to_string())]);
190    }
191    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
192        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
193    }
194    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
195        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
196    };
197
198    let local_var_req = local_var_req_builder.build()?;
199    let local_var_resp = local_var_client.execute(local_var_req).await?;
200
201    let local_var_status = local_var_resp.status();
202    let local_var_content = local_var_resp.text().await?;
203
204    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
205        serde_json::from_str(&local_var_content).map_err(Error::from)
206    } else {
207        let local_var_entity: Option<GetUserThreadsError> = serde_json::from_str(&local_var_content).ok();
208        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
209        Err(Error::ResponseError(local_var_error))
210    }
211}
212
213/// Mark a thread that user is following as unread  __Minimum server version__: 6.7  ##### Permissions Must have `read_channel` permission for the channel the thread is in or if the channel is public, have the `read_public_channels` permission for the team.  Must have `edit_other_users` permission if the user is not the one marking the thread for himself. 
214pub async fn set_thread_unread_by_post_id(configuration: &configuration::Configuration, user_id: &str, team_id: &str, thread_id: &str, post_id: &str) -> Result<(), Error<SetThreadUnreadByPostIdError>> {
215    let local_var_configuration = configuration;
216
217    let local_var_client = &local_var_configuration.client;
218
219    let local_var_uri_str = format!("{}/users/{user_id}/teams/{team_id}/threads/{thread_id}/set_unread/{post_id}", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id), team_id=crate::apis::urlencode(team_id), thread_id=crate::apis::urlencode(thread_id), post_id=crate::apis::urlencode(post_id));
220    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
221
222    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
223        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
224    }
225    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
226        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
227    };
228
229    let local_var_req = local_var_req_builder.build()?;
230    let local_var_resp = local_var_client.execute(local_var_req).await?;
231
232    let local_var_status = local_var_resp.status();
233    let local_var_content = local_var_resp.text().await?;
234
235    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
236        Ok(())
237    } else {
238        let local_var_entity: Option<SetThreadUnreadByPostIdError> = serde_json::from_str(&local_var_content).ok();
239        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
240        Err(Error::ResponseError(local_var_error))
241    }
242}
243
244/// Start following a thread  __Minimum server version__: 5.29  ##### Permissions Must be logged in as the user or have `edit_other_users` permission. 
245pub async fn start_following_thread(configuration: &configuration::Configuration, user_id: &str, team_id: &str, thread_id: &str) -> Result<(), Error<StartFollowingThreadError>> {
246    let local_var_configuration = configuration;
247
248    let local_var_client = &local_var_configuration.client;
249
250    let local_var_uri_str = format!("{}/users/{user_id}/teams/{team_id}/threads/{thread_id}/following", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id), team_id=crate::apis::urlencode(team_id), thread_id=crate::apis::urlencode(thread_id));
251    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
252
253    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
254        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
255    }
256    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
257        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
258    };
259
260    let local_var_req = local_var_req_builder.build()?;
261    let local_var_resp = local_var_client.execute(local_var_req).await?;
262
263    let local_var_status = local_var_resp.status();
264    let local_var_content = local_var_resp.text().await?;
265
266    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
267        Ok(())
268    } else {
269        let local_var_entity: Option<StartFollowingThreadError> = serde_json::from_str(&local_var_content).ok();
270        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
271        Err(Error::ResponseError(local_var_error))
272    }
273}
274
275/// Stop following a thread  __Minimum server version__: 5.29  ##### Permissions Must be logged in as the user or have `edit_other_users` permission. 
276pub async fn stop_following_thread(configuration: &configuration::Configuration, user_id: &str, team_id: &str, thread_id: &str) -> Result<(), Error<StopFollowingThreadError>> {
277    let local_var_configuration = configuration;
278
279    let local_var_client = &local_var_configuration.client;
280
281    let local_var_uri_str = format!("{}/users/{user_id}/teams/{team_id}/threads/{thread_id}/following", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id), team_id=crate::apis::urlencode(team_id), thread_id=crate::apis::urlencode(thread_id));
282    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
283
284    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
285        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
286    }
287    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
288        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
289    };
290
291    let local_var_req = local_var_req_builder.build()?;
292    let local_var_resp = local_var_client.execute(local_var_req).await?;
293
294    let local_var_status = local_var_resp.status();
295    let local_var_content = local_var_resp.text().await?;
296
297    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
298        Ok(())
299    } else {
300        let local_var_entity: Option<StopFollowingThreadError> = serde_json::from_str(&local_var_content).ok();
301        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
302        Err(Error::ResponseError(local_var_error))
303    }
304}
305
306/// Mark a thread that user is following as read  __Minimum server version__: 5.29  ##### Permissions Must be logged in as the user or have `edit_other_users` permission. 
307pub async fn update_thread_read_for_user(configuration: &configuration::Configuration, user_id: &str, team_id: &str, thread_id: &str, timestamp: &str) -> Result<(), Error<UpdateThreadReadForUserError>> {
308    let local_var_configuration = configuration;
309
310    let local_var_client = &local_var_configuration.client;
311
312    let local_var_uri_str = format!("{}/users/{user_id}/teams/{team_id}/threads/{thread_id}/read/{timestamp}", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id), team_id=crate::apis::urlencode(team_id), thread_id=crate::apis::urlencode(thread_id), timestamp=crate::apis::urlencode(timestamp));
313    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
314
315    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
316        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
317    }
318    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
319        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
320    };
321
322    let local_var_req = local_var_req_builder.build()?;
323    let local_var_resp = local_var_client.execute(local_var_req).await?;
324
325    let local_var_status = local_var_resp.status();
326    let local_var_content = local_var_resp.text().await?;
327
328    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
329        Ok(())
330    } else {
331        let local_var_entity: Option<UpdateThreadReadForUserError> = serde_json::from_str(&local_var_content).ok();
332        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
333        Err(Error::ResponseError(local_var_error))
334    }
335}
336
337/// Mark all threads that user is following as read  __Minimum server version__: 5.29  ##### Permissions Must be logged in as the user or have `edit_other_users` permission. 
338pub async fn update_threads_read_for_user(configuration: &configuration::Configuration, user_id: &str, team_id: &str) -> Result<(), Error<UpdateThreadsReadForUserError>> {
339    let local_var_configuration = configuration;
340
341    let local_var_client = &local_var_configuration.client;
342
343    let local_var_uri_str = format!("{}/users/{user_id}/teams/{team_id}/threads/read", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id), team_id=crate::apis::urlencode(team_id));
344    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
345
346    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
347        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
348    }
349    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
350        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
351    };
352
353    let local_var_req = local_var_req_builder.build()?;
354    let local_var_resp = local_var_client.execute(local_var_req).await?;
355
356    let local_var_status = local_var_resp.status();
357    let local_var_content = local_var_resp.text().await?;
358
359    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
360        Ok(())
361    } else {
362        let local_var_entity: Option<UpdateThreadsReadForUserError> = serde_json::from_str(&local_var_content).ok();
363        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
364        Err(Error::ResponseError(local_var_error))
365    }
366}
367