mattermost_rust_client/apis/
posts_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 [`create_post`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreatePostError {
22    Status400(crate::models::AppError),
23    Status401(crate::models::AppError),
24    Status403(crate::models::AppError),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`create_post_ephemeral`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum CreatePostEphemeralError {
32    Status400(crate::models::AppError),
33    Status401(crate::models::AppError),
34    Status403(crate::models::AppError),
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`delete_post`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum DeletePostError {
42    Status400(crate::models::AppError),
43    Status401(crate::models::AppError),
44    Status403(crate::models::AppError),
45    UnknownValue(serde_json::Value),
46}
47
48/// struct for typed errors of method [`do_post_action`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum DoPostActionError {
52    Status400(crate::models::AppError),
53    Status401(crate::models::AppError),
54    Status403(crate::models::AppError),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`get_file_infos_for_post`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum GetFileInfosForPostError {
62    Status400(crate::models::AppError),
63    Status401(crate::models::AppError),
64    Status403(crate::models::AppError),
65    UnknownValue(serde_json::Value),
66}
67
68/// struct for typed errors of method [`get_flagged_posts_for_user`]
69#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum GetFlaggedPostsForUserError {
72    Status400(crate::models::AppError),
73    Status401(crate::models::AppError),
74    Status403(crate::models::AppError),
75    UnknownValue(serde_json::Value),
76}
77
78/// struct for typed errors of method [`get_post`]
79#[derive(Debug, Clone, Serialize, Deserialize)]
80#[serde(untagged)]
81pub enum GetPostError {
82    Status400(crate::models::AppError),
83    Status401(crate::models::AppError),
84    Status403(crate::models::AppError),
85    UnknownValue(serde_json::Value),
86}
87
88/// struct for typed errors of method [`get_post_thread`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum GetPostThreadError {
92    Status400(crate::models::AppError),
93    Status401(crate::models::AppError),
94    Status403(crate::models::AppError),
95    UnknownValue(serde_json::Value),
96}
97
98/// struct for typed errors of method [`get_posts_around_last_unread`]
99#[derive(Debug, Clone, Serialize, Deserialize)]
100#[serde(untagged)]
101pub enum GetPostsAroundLastUnreadError {
102    Status400(crate::models::AppError),
103    Status401(crate::models::AppError),
104    Status403(crate::models::AppError),
105    UnknownValue(serde_json::Value),
106}
107
108/// struct for typed errors of method [`get_posts_by_ids`]
109#[derive(Debug, Clone, Serialize, Deserialize)]
110#[serde(untagged)]
111pub enum GetPostsByIdsError {
112    Status400(crate::models::AppError),
113    Status401(crate::models::AppError),
114    Status403(crate::models::AppError),
115    UnknownValue(serde_json::Value),
116}
117
118/// struct for typed errors of method [`get_posts_for_channel`]
119#[derive(Debug, Clone, Serialize, Deserialize)]
120#[serde(untagged)]
121pub enum GetPostsForChannelError {
122    Status400(crate::models::AppError),
123    Status401(crate::models::AppError),
124    Status403(crate::models::AppError),
125    UnknownValue(serde_json::Value),
126}
127
128/// struct for typed errors of method [`patch_post`]
129#[derive(Debug, Clone, Serialize, Deserialize)]
130#[serde(untagged)]
131pub enum PatchPostError {
132    Status400(crate::models::AppError),
133    Status401(crate::models::AppError),
134    Status403(crate::models::AppError),
135    UnknownValue(serde_json::Value),
136}
137
138/// struct for typed errors of method [`pin_post`]
139#[derive(Debug, Clone, Serialize, Deserialize)]
140#[serde(untagged)]
141pub enum PinPostError {
142    Status400(crate::models::AppError),
143    Status401(crate::models::AppError),
144    Status403(crate::models::AppError),
145    UnknownValue(serde_json::Value),
146}
147
148/// struct for typed errors of method [`search_posts`]
149#[derive(Debug, Clone, Serialize, Deserialize)]
150#[serde(untagged)]
151pub enum SearchPostsError {
152    Status400(crate::models::AppError),
153    Status401(crate::models::AppError),
154    Status403(crate::models::AppError),
155    UnknownValue(serde_json::Value),
156}
157
158/// struct for typed errors of method [`set_post_reminder`]
159#[derive(Debug, Clone, Serialize, Deserialize)]
160#[serde(untagged)]
161pub enum SetPostReminderError {
162    Status400(crate::models::AppError),
163    Status401(crate::models::AppError),
164    Status403(crate::models::AppError),
165    Status404(crate::models::AppError),
166    UnknownValue(serde_json::Value),
167}
168
169/// struct for typed errors of method [`set_post_unread`]
170#[derive(Debug, Clone, Serialize, Deserialize)]
171#[serde(untagged)]
172pub enum SetPostUnreadError {
173    Status400(crate::models::AppError),
174    Status401(crate::models::AppError),
175    Status403(crate::models::AppError),
176    Status404(crate::models::AppError),
177    UnknownValue(serde_json::Value),
178}
179
180/// struct for typed errors of method [`unpin_post`]
181#[derive(Debug, Clone, Serialize, Deserialize)]
182#[serde(untagged)]
183pub enum UnpinPostError {
184    Status400(crate::models::AppError),
185    Status401(crate::models::AppError),
186    Status403(crate::models::AppError),
187    UnknownValue(serde_json::Value),
188}
189
190/// struct for typed errors of method [`update_post`]
191#[derive(Debug, Clone, Serialize, Deserialize)]
192#[serde(untagged)]
193pub enum UpdatePostError {
194    Status400(crate::models::AppError),
195    Status401(crate::models::AppError),
196    Status403(crate::models::AppError),
197    UnknownValue(serde_json::Value),
198}
199
200
201/// Create a new post in a channel. To create the post as a comment on another post, provide `root_id`. ##### Permissions Must have `create_post` permission for the channel the post is being created in. 
202pub async fn create_post(configuration: &configuration::Configuration, create_post_request: crate::models::CreatePostRequest, set_online: Option<bool>) -> Result<crate::models::Post, Error<CreatePostError>> {
203    let local_var_configuration = configuration;
204
205    let local_var_client = &local_var_configuration.client;
206
207    let local_var_uri_str = format!("{}/posts", local_var_configuration.base_path);
208    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
209
210    if let Some(ref local_var_str) = set_online {
211        local_var_req_builder = local_var_req_builder.query(&[("set_online", &local_var_str.to_string())]);
212    }
213    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
214        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
215    }
216    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
217        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
218    };
219    local_var_req_builder = local_var_req_builder.json(&create_post_request);
220
221    let local_var_req = local_var_req_builder.build()?;
222    let local_var_resp = local_var_client.execute(local_var_req).await?;
223
224    let local_var_status = local_var_resp.status();
225    let local_var_content = local_var_resp.text().await?;
226
227    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
228        serde_json::from_str(&local_var_content).map_err(Error::from)
229    } else {
230        let local_var_entity: Option<CreatePostError> = serde_json::from_str(&local_var_content).ok();
231        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
232        Err(Error::ResponseError(local_var_error))
233    }
234}
235
236/// Create a new ephemeral post in a channel. ##### Permissions Must have `create_post_ephemeral` permission (currently only given to system admin) 
237pub async fn create_post_ephemeral(configuration: &configuration::Configuration, create_post_ephemeral_request: crate::models::CreatePostEphemeralRequest) -> Result<crate::models::Post, Error<CreatePostEphemeralError>> {
238    let local_var_configuration = configuration;
239
240    let local_var_client = &local_var_configuration.client;
241
242    let local_var_uri_str = format!("{}/posts/ephemeral", local_var_configuration.base_path);
243    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
244
245    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
246        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
247    }
248    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
249        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
250    };
251    local_var_req_builder = local_var_req_builder.json(&create_post_ephemeral_request);
252
253    let local_var_req = local_var_req_builder.build()?;
254    let local_var_resp = local_var_client.execute(local_var_req).await?;
255
256    let local_var_status = local_var_resp.status();
257    let local_var_content = local_var_resp.text().await?;
258
259    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
260        serde_json::from_str(&local_var_content).map_err(Error::from)
261    } else {
262        let local_var_entity: Option<CreatePostEphemeralError> = serde_json::from_str(&local_var_content).ok();
263        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
264        Err(Error::ResponseError(local_var_error))
265    }
266}
267
268/// Soft deletes a post, by marking the post as deleted in the database. Soft deleted posts will not be returned in post queries. ##### Permissions Must be logged in as the user or have `delete_others_posts` permission. 
269pub async fn delete_post(configuration: &configuration::Configuration, post_id: &str) -> Result<crate::models::StatusOk, Error<DeletePostError>> {
270    let local_var_configuration = configuration;
271
272    let local_var_client = &local_var_configuration.client;
273
274    let local_var_uri_str = format!("{}/posts/{post_id}", local_var_configuration.base_path, post_id=crate::apis::urlencode(post_id));
275    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
276
277    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
278        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
279    }
280    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
281        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
282    };
283
284    let local_var_req = local_var_req_builder.build()?;
285    let local_var_resp = local_var_client.execute(local_var_req).await?;
286
287    let local_var_status = local_var_resp.status();
288    let local_var_content = local_var_resp.text().await?;
289
290    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
291        serde_json::from_str(&local_var_content).map_err(Error::from)
292    } else {
293        let local_var_entity: Option<DeletePostError> = serde_json::from_str(&local_var_content).ok();
294        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
295        Err(Error::ResponseError(local_var_error))
296    }
297}
298
299/// Perform a post action, which allows users to interact with integrations through posts. ##### Permissions Must be authenticated and have the `read_channel` permission to the channel the post is in. 
300pub async fn do_post_action(configuration: &configuration::Configuration, post_id: &str, action_id: &str) -> Result<crate::models::StatusOk, Error<DoPostActionError>> {
301    let local_var_configuration = configuration;
302
303    let local_var_client = &local_var_configuration.client;
304
305    let local_var_uri_str = format!("{}/posts/{post_id}/actions/{action_id}", local_var_configuration.base_path, post_id=crate::apis::urlencode(post_id), action_id=crate::apis::urlencode(action_id));
306    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
307
308    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
309        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
310    }
311    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
312        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
313    };
314
315    let local_var_req = local_var_req_builder.build()?;
316    let local_var_resp = local_var_client.execute(local_var_req).await?;
317
318    let local_var_status = local_var_resp.status();
319    let local_var_content = local_var_resp.text().await?;
320
321    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
322        serde_json::from_str(&local_var_content).map_err(Error::from)
323    } else {
324        let local_var_entity: Option<DoPostActionError> = serde_json::from_str(&local_var_content).ok();
325        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
326        Err(Error::ResponseError(local_var_error))
327    }
328}
329
330/// Gets a list of file information objects for the files attached to a post. ##### Permissions Must have `read_channel` permission for the channel the post is in. 
331pub async fn get_file_infos_for_post(configuration: &configuration::Configuration, post_id: &str, include_deleted: Option<bool>) -> Result<Vec<crate::models::FileInfo>, Error<GetFileInfosForPostError>> {
332    let local_var_configuration = configuration;
333
334    let local_var_client = &local_var_configuration.client;
335
336    let local_var_uri_str = format!("{}/posts/{post_id}/files/info", local_var_configuration.base_path, post_id=crate::apis::urlencode(post_id));
337    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
338
339    if let Some(ref local_var_str) = include_deleted {
340        local_var_req_builder = local_var_req_builder.query(&[("include_deleted", &local_var_str.to_string())]);
341    }
342    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
343        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
344    }
345    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
346        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
347    };
348
349    let local_var_req = local_var_req_builder.build()?;
350    let local_var_resp = local_var_client.execute(local_var_req).await?;
351
352    let local_var_status = local_var_resp.status();
353    let local_var_content = local_var_resp.text().await?;
354
355    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
356        serde_json::from_str(&local_var_content).map_err(Error::from)
357    } else {
358        let local_var_entity: Option<GetFileInfosForPostError> = serde_json::from_str(&local_var_content).ok();
359        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
360        Err(Error::ResponseError(local_var_error))
361    }
362}
363
364/// Get a page of flagged posts of a user provided user id string. Selects from a channel, team, or all flagged posts by a user. Will only return posts from channels in which the user is member. ##### Permissions Must be user or have `manage_system` permission. 
365pub async fn get_flagged_posts_for_user(configuration: &configuration::Configuration, user_id: &str, team_id: Option<&str>, channel_id: Option<&str>, page: Option<i32>, per_page: Option<i32>) -> Result<Vec<crate::models::PostList>, Error<GetFlaggedPostsForUserError>> {
366    let local_var_configuration = configuration;
367
368    let local_var_client = &local_var_configuration.client;
369
370    let local_var_uri_str = format!("{}/users/{user_id}/posts/flagged", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id));
371    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
372
373    if let Some(ref local_var_str) = team_id {
374        local_var_req_builder = local_var_req_builder.query(&[("team_id", &local_var_str.to_string())]);
375    }
376    if let Some(ref local_var_str) = channel_id {
377        local_var_req_builder = local_var_req_builder.query(&[("channel_id", &local_var_str.to_string())]);
378    }
379    if let Some(ref local_var_str) = page {
380        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
381    }
382    if let Some(ref local_var_str) = per_page {
383        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
384    }
385    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
386        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
387    }
388    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
389        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
390    };
391
392    let local_var_req = local_var_req_builder.build()?;
393    let local_var_resp = local_var_client.execute(local_var_req).await?;
394
395    let local_var_status = local_var_resp.status();
396    let local_var_content = local_var_resp.text().await?;
397
398    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
399        serde_json::from_str(&local_var_content).map_err(Error::from)
400    } else {
401        let local_var_entity: Option<GetFlaggedPostsForUserError> = serde_json::from_str(&local_var_content).ok();
402        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
403        Err(Error::ResponseError(local_var_error))
404    }
405}
406
407/// Get a single post. ##### Permissions Must have `read_channel` permission for the channel the post is in or if the channel is public, have the `read_public_channels` permission for the team. 
408pub async fn get_post(configuration: &configuration::Configuration, post_id: &str, include_deleted: Option<bool>) -> Result<crate::models::Post, Error<GetPostError>> {
409    let local_var_configuration = configuration;
410
411    let local_var_client = &local_var_configuration.client;
412
413    let local_var_uri_str = format!("{}/posts/{post_id}", local_var_configuration.base_path, post_id=crate::apis::urlencode(post_id));
414    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
415
416    if let Some(ref local_var_str) = include_deleted {
417        local_var_req_builder = local_var_req_builder.query(&[("include_deleted", &local_var_str.to_string())]);
418    }
419    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
420        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
421    }
422    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
423        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
424    };
425
426    let local_var_req = local_var_req_builder.build()?;
427    let local_var_resp = local_var_client.execute(local_var_req).await?;
428
429    let local_var_status = local_var_resp.status();
430    let local_var_content = local_var_resp.text().await?;
431
432    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
433        serde_json::from_str(&local_var_content).map_err(Error::from)
434    } else {
435        let local_var_entity: Option<GetPostError> = serde_json::from_str(&local_var_content).ok();
436        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
437        Err(Error::ResponseError(local_var_error))
438    }
439}
440
441/// Get a post and the rest of the posts in the same thread. ##### Permissions Must have `read_channel` permission for the channel the post is in or if the channel is public, have the `read_public_channels` permission for the team. 
442pub async fn get_post_thread(configuration: &configuration::Configuration, post_id: &str, per_page: Option<i32>, from_post: Option<&str>, from_create_at: Option<i32>, direction: Option<&str>, skip_fetch_threads: Option<bool>, collapsed_threads: Option<bool>, collapsed_threads_extended: Option<bool>) -> Result<crate::models::PostList, Error<GetPostThreadError>> {
443    let local_var_configuration = configuration;
444
445    let local_var_client = &local_var_configuration.client;
446
447    let local_var_uri_str = format!("{}/posts/{post_id}/thread", local_var_configuration.base_path, post_id=crate::apis::urlencode(post_id));
448    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
449
450    if let Some(ref local_var_str) = per_page {
451        local_var_req_builder = local_var_req_builder.query(&[("perPage", &local_var_str.to_string())]);
452    }
453    if let Some(ref local_var_str) = from_post {
454        local_var_req_builder = local_var_req_builder.query(&[("fromPost", &local_var_str.to_string())]);
455    }
456    if let Some(ref local_var_str) = from_create_at {
457        local_var_req_builder = local_var_req_builder.query(&[("fromCreateAt", &local_var_str.to_string())]);
458    }
459    if let Some(ref local_var_str) = direction {
460        local_var_req_builder = local_var_req_builder.query(&[("direction", &local_var_str.to_string())]);
461    }
462    if let Some(ref local_var_str) = skip_fetch_threads {
463        local_var_req_builder = local_var_req_builder.query(&[("skipFetchThreads", &local_var_str.to_string())]);
464    }
465    if let Some(ref local_var_str) = collapsed_threads {
466        local_var_req_builder = local_var_req_builder.query(&[("collapsedThreads", &local_var_str.to_string())]);
467    }
468    if let Some(ref local_var_str) = collapsed_threads_extended {
469        local_var_req_builder = local_var_req_builder.query(&[("collapsedThreadsExtended", &local_var_str.to_string())]);
470    }
471    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
472        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
473    }
474    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
475        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
476    };
477
478    let local_var_req = local_var_req_builder.build()?;
479    let local_var_resp = local_var_client.execute(local_var_req).await?;
480
481    let local_var_status = local_var_resp.status();
482    let local_var_content = local_var_resp.text().await?;
483
484    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
485        serde_json::from_str(&local_var_content).map_err(Error::from)
486    } else {
487        let local_var_entity: Option<GetPostThreadError> = serde_json::from_str(&local_var_content).ok();
488        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
489        Err(Error::ResponseError(local_var_error))
490    }
491}
492
493/// Get the oldest unread post in the channel for the given user as well as the posts around it. The returned list is sorted in descending order (most recent post first). ##### Permissions Must be logged in as the user or have `edit_other_users` permission, and must have `read_channel` permission for the channel. __Minimum server version__: 5.14 
494pub async fn get_posts_around_last_unread(configuration: &configuration::Configuration, user_id: &str, channel_id: &str, limit_before: Option<i32>, limit_after: Option<i32>, skip_fetch_threads: Option<bool>, collapsed_threads: Option<bool>, collapsed_threads_extended: Option<bool>) -> Result<crate::models::PostList, Error<GetPostsAroundLastUnreadError>> {
495    let local_var_configuration = configuration;
496
497    let local_var_client = &local_var_configuration.client;
498
499    let local_var_uri_str = format!("{}/users/{user_id}/channels/{channel_id}/posts/unread", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id), channel_id=crate::apis::urlencode(channel_id));
500    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
501
502    if let Some(ref local_var_str) = limit_before {
503        local_var_req_builder = local_var_req_builder.query(&[("limit_before", &local_var_str.to_string())]);
504    }
505    if let Some(ref local_var_str) = limit_after {
506        local_var_req_builder = local_var_req_builder.query(&[("limit_after", &local_var_str.to_string())]);
507    }
508    if let Some(ref local_var_str) = skip_fetch_threads {
509        local_var_req_builder = local_var_req_builder.query(&[("skipFetchThreads", &local_var_str.to_string())]);
510    }
511    if let Some(ref local_var_str) = collapsed_threads {
512        local_var_req_builder = local_var_req_builder.query(&[("collapsedThreads", &local_var_str.to_string())]);
513    }
514    if let Some(ref local_var_str) = collapsed_threads_extended {
515        local_var_req_builder = local_var_req_builder.query(&[("collapsedThreadsExtended", &local_var_str.to_string())]);
516    }
517    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
518        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
519    }
520    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
521        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
522    };
523
524    let local_var_req = local_var_req_builder.build()?;
525    let local_var_resp = local_var_client.execute(local_var_req).await?;
526
527    let local_var_status = local_var_resp.status();
528    let local_var_content = local_var_resp.text().await?;
529
530    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
531        serde_json::from_str(&local_var_content).map_err(Error::from)
532    } else {
533        let local_var_entity: Option<GetPostsAroundLastUnreadError> = serde_json::from_str(&local_var_content).ok();
534        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
535        Err(Error::ResponseError(local_var_error))
536    }
537}
538
539/// Fetch a list of posts based on the provided postIDs ##### Permissions Must have `read_channel` permission for the channel the post is in or if the channel is public, have the `read_public_channels` permission for the team. 
540pub async fn get_posts_by_ids(configuration: &configuration::Configuration, request_body: Vec<String>) -> Result<Vec<crate::models::Post>, Error<GetPostsByIdsError>> {
541    let local_var_configuration = configuration;
542
543    let local_var_client = &local_var_configuration.client;
544
545    let local_var_uri_str = format!("{}/posts/ids", local_var_configuration.base_path);
546    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
547
548    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
549        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
550    }
551    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
552        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
553    };
554    local_var_req_builder = local_var_req_builder.json(&request_body);
555
556    let local_var_req = local_var_req_builder.build()?;
557    let local_var_resp = local_var_client.execute(local_var_req).await?;
558
559    let local_var_status = local_var_resp.status();
560    let local_var_content = local_var_resp.text().await?;
561
562    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
563        serde_json::from_str(&local_var_content).map_err(Error::from)
564    } else {
565        let local_var_entity: Option<GetPostsByIdsError> = serde_json::from_str(&local_var_content).ok();
566        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
567        Err(Error::ResponseError(local_var_error))
568    }
569}
570
571/// Get a page of posts in a channel. Use the query parameters to modify the behaviour of this endpoint. The parameter `since` must not be used with any of `before`, `after`, `page`, and `per_page` parameters. If `since` is used, it will always return all posts modified since that time, ordered by their create time limited till 1000. A caveat with this parameter is that there is no guarantee that the returned posts will be consecutive. It is left to the clients to maintain state and fill any missing holes in the post order. ##### Permissions Must have `read_channel` permission for the channel. 
572pub async fn get_posts_for_channel(configuration: &configuration::Configuration, channel_id: &str, page: Option<i32>, per_page: Option<i32>, since: Option<i32>, before: Option<&str>, after: Option<&str>, include_deleted: Option<bool>) -> Result<crate::models::PostList, Error<GetPostsForChannelError>> {
573    let local_var_configuration = configuration;
574
575    let local_var_client = &local_var_configuration.client;
576
577    let local_var_uri_str = format!("{}/channels/{channel_id}/posts", local_var_configuration.base_path, channel_id=crate::apis::urlencode(channel_id));
578    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
579
580    if let Some(ref local_var_str) = page {
581        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
582    }
583    if let Some(ref local_var_str) = per_page {
584        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
585    }
586    if let Some(ref local_var_str) = since {
587        local_var_req_builder = local_var_req_builder.query(&[("since", &local_var_str.to_string())]);
588    }
589    if let Some(ref local_var_str) = before {
590        local_var_req_builder = local_var_req_builder.query(&[("before", &local_var_str.to_string())]);
591    }
592    if let Some(ref local_var_str) = after {
593        local_var_req_builder = local_var_req_builder.query(&[("after", &local_var_str.to_string())]);
594    }
595    if let Some(ref local_var_str) = include_deleted {
596        local_var_req_builder = local_var_req_builder.query(&[("include_deleted", &local_var_str.to_string())]);
597    }
598    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
599        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
600    }
601    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
602        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
603    };
604
605    let local_var_req = local_var_req_builder.build()?;
606    let local_var_resp = local_var_client.execute(local_var_req).await?;
607
608    let local_var_status = local_var_resp.status();
609    let local_var_content = local_var_resp.text().await?;
610
611    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
612        serde_json::from_str(&local_var_content).map_err(Error::from)
613    } else {
614        let local_var_entity: Option<GetPostsForChannelError> = serde_json::from_str(&local_var_content).ok();
615        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
616        Err(Error::ResponseError(local_var_error))
617    }
618}
619
620/// Partially update a post by providing only the fields you want to update. Omitted fields will not be updated. The fields that can be updated are defined in the request body, all other provided fields will be ignored. ##### Permissions Must have the `edit_post` permission. 
621pub async fn patch_post(configuration: &configuration::Configuration, post_id: &str, patch_post_request: crate::models::PatchPostRequest) -> Result<crate::models::Post, Error<PatchPostError>> {
622    let local_var_configuration = configuration;
623
624    let local_var_client = &local_var_configuration.client;
625
626    let local_var_uri_str = format!("{}/posts/{post_id}/patch", local_var_configuration.base_path, post_id=crate::apis::urlencode(post_id));
627    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
628
629    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
630        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
631    }
632    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
633        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
634    };
635    local_var_req_builder = local_var_req_builder.json(&patch_post_request);
636
637    let local_var_req = local_var_req_builder.build()?;
638    let local_var_resp = local_var_client.execute(local_var_req).await?;
639
640    let local_var_status = local_var_resp.status();
641    let local_var_content = local_var_resp.text().await?;
642
643    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
644        serde_json::from_str(&local_var_content).map_err(Error::from)
645    } else {
646        let local_var_entity: Option<PatchPostError> = serde_json::from_str(&local_var_content).ok();
647        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
648        Err(Error::ResponseError(local_var_error))
649    }
650}
651
652/// Pin a post to a channel it is in based from the provided post id string. ##### Permissions Must be authenticated and have the `read_channel` permission to the channel the post is in. 
653pub async fn pin_post(configuration: &configuration::Configuration, post_id: &str) -> Result<crate::models::StatusOk, Error<PinPostError>> {
654    let local_var_configuration = configuration;
655
656    let local_var_client = &local_var_configuration.client;
657
658    let local_var_uri_str = format!("{}/posts/{post_id}/pin", local_var_configuration.base_path, post_id=crate::apis::urlencode(post_id));
659    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
660
661    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
662        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
663    }
664    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
665        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
666    };
667
668    let local_var_req = local_var_req_builder.build()?;
669    let local_var_resp = local_var_client.execute(local_var_req).await?;
670
671    let local_var_status = local_var_resp.status();
672    let local_var_content = local_var_resp.text().await?;
673
674    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
675        serde_json::from_str(&local_var_content).map_err(Error::from)
676    } else {
677        let local_var_entity: Option<PinPostError> = serde_json::from_str(&local_var_content).ok();
678        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
679        Err(Error::ResponseError(local_var_error))
680    }
681}
682
683/// Search posts in the team and from the provided terms string. ##### Permissions Must be authenticated and have the `view_team` permission. 
684pub async fn search_posts(configuration: &configuration::Configuration, team_id: &str, search_posts_request: crate::models::SearchPostsRequest) -> Result<crate::models::PostListWithSearchMatches, Error<SearchPostsError>> {
685    let local_var_configuration = configuration;
686
687    let local_var_client = &local_var_configuration.client;
688
689    let local_var_uri_str = format!("{}/teams/{team_id}/posts/search", local_var_configuration.base_path, team_id=crate::apis::urlencode(team_id));
690    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
691
692    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
693        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
694    }
695    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
696        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
697    };
698    local_var_req_builder = local_var_req_builder.json(&search_posts_request);
699
700    let local_var_req = local_var_req_builder.build()?;
701    let local_var_resp = local_var_client.execute(local_var_req).await?;
702
703    let local_var_status = local_var_resp.status();
704    let local_var_content = local_var_resp.text().await?;
705
706    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
707        serde_json::from_str(&local_var_content).map_err(Error::from)
708    } else {
709        let local_var_entity: Option<SearchPostsError> = serde_json::from_str(&local_var_content).ok();
710        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
711        Err(Error::ResponseError(local_var_error))
712    }
713}
714
715/// Set a reminder for the user for the post. ##### Permissions Must have `read_channel` permission for the channel the post is in.  __Minimum server version__: 7.2 
716pub async fn set_post_reminder(configuration: &configuration::Configuration, user_id: &str, post_id: &str, set_post_reminder_request: crate::models::SetPostReminderRequest) -> Result<crate::models::StatusOk, Error<SetPostReminderError>> {
717    let local_var_configuration = configuration;
718
719    let local_var_client = &local_var_configuration.client;
720
721    let local_var_uri_str = format!("{}/users/{user_id}/posts/{post_id}/reminder", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id), post_id=crate::apis::urlencode(post_id));
722    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
723
724    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
725        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
726    }
727    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
728        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
729    };
730    local_var_req_builder = local_var_req_builder.json(&set_post_reminder_request);
731
732    let local_var_req = local_var_req_builder.build()?;
733    let local_var_resp = local_var_client.execute(local_var_req).await?;
734
735    let local_var_status = local_var_resp.status();
736    let local_var_content = local_var_resp.text().await?;
737
738    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
739        serde_json::from_str(&local_var_content).map_err(Error::from)
740    } else {
741        let local_var_entity: Option<SetPostReminderError> = serde_json::from_str(&local_var_content).ok();
742        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
743        Err(Error::ResponseError(local_var_error))
744    }
745}
746
747/// Mark a channel as being unread from a given post. ##### Permissions Must have `read_channel` permission for the channel the post 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 post for himself.  __Minimum server version__: 5.18 
748pub async fn set_post_unread(configuration: &configuration::Configuration, user_id: &str, post_id: &str) -> Result<crate::models::ChannelUnreadAt, Error<SetPostUnreadError>> {
749    let local_var_configuration = configuration;
750
751    let local_var_client = &local_var_configuration.client;
752
753    let local_var_uri_str = format!("{}/users/{user_id}/posts/{post_id}/set_unread", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id), post_id=crate::apis::urlencode(post_id));
754    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
755
756    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
757        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
758    }
759    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
760        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
761    };
762
763    let local_var_req = local_var_req_builder.build()?;
764    let local_var_resp = local_var_client.execute(local_var_req).await?;
765
766    let local_var_status = local_var_resp.status();
767    let local_var_content = local_var_resp.text().await?;
768
769    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
770        serde_json::from_str(&local_var_content).map_err(Error::from)
771    } else {
772        let local_var_entity: Option<SetPostUnreadError> = serde_json::from_str(&local_var_content).ok();
773        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
774        Err(Error::ResponseError(local_var_error))
775    }
776}
777
778/// Unpin a post to a channel it is in based from the provided post id string. ##### Permissions Must be authenticated and have the `read_channel` permission to the channel the post is in. 
779pub async fn unpin_post(configuration: &configuration::Configuration, post_id: &str) -> Result<crate::models::StatusOk, Error<UnpinPostError>> {
780    let local_var_configuration = configuration;
781
782    let local_var_client = &local_var_configuration.client;
783
784    let local_var_uri_str = format!("{}/posts/{post_id}/unpin", local_var_configuration.base_path, post_id=crate::apis::urlencode(post_id));
785    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
786
787    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
788        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
789    }
790    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
791        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
792    };
793
794    let local_var_req = local_var_req_builder.build()?;
795    let local_var_resp = local_var_client.execute(local_var_req).await?;
796
797    let local_var_status = local_var_resp.status();
798    let local_var_content = local_var_resp.text().await?;
799
800    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
801        serde_json::from_str(&local_var_content).map_err(Error::from)
802    } else {
803        let local_var_entity: Option<UnpinPostError> = serde_json::from_str(&local_var_content).ok();
804        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
805        Err(Error::ResponseError(local_var_error))
806    }
807}
808
809/// Update a post. Only the fields listed below are updatable, omitted fields will be treated as blank. ##### Permissions Must have `edit_post` permission for the channel the post is in. 
810pub async fn update_post(configuration: &configuration::Configuration, post_id: &str, update_post_request: crate::models::UpdatePostRequest) -> Result<crate::models::Post, Error<UpdatePostError>> {
811    let local_var_configuration = configuration;
812
813    let local_var_client = &local_var_configuration.client;
814
815    let local_var_uri_str = format!("{}/posts/{post_id}", local_var_configuration.base_path, post_id=crate::apis::urlencode(post_id));
816    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
817
818    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
819        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
820    }
821    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
822        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
823    };
824    local_var_req_builder = local_var_req_builder.json(&update_post_request);
825
826    let local_var_req = local_var_req_builder.build()?;
827    let local_var_resp = local_var_client.execute(local_var_req).await?;
828
829    let local_var_status = local_var_resp.status();
830    let local_var_content = local_var_resp.text().await?;
831
832    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
833        serde_json::from_str(&local_var_content).map_err(Error::from)
834    } else {
835        let local_var_entity: Option<UpdatePostError> = serde_json::from_str(&local_var_content).ok();
836        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
837        Err(Error::ResponseError(local_var_error))
838    }
839}
840