/*
* Mattermost API Reference
*
* There is also a work-in-progress [Postman API reference](https://documenter.getpostman.com/view/4508214/RW8FERUn).
*
* The version of the OpenAPI document: 4.0.0
* Contact: feedback@mattermost.com
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use super::ResponseContent;
use super::{Error, configuration};
/// struct for passing parameters to the method [`create_post`]
#[derive(Clone, Debug, Default)]
pub struct CreatePostParams {
/// Post object to create
pub create_post_request: crate::openapi::models::CreatePostRequest,
/// Whether to set the user status as online or not.
pub set_online: Option<bool>,
}
/// struct for passing parameters to the method [`create_post_ephemeral`]
#[derive(Clone, Debug, Default)]
pub struct CreatePostEphemeralParams {
/// Ephemeral Post object to send
pub create_post_ephemeral_request: crate::openapi::models::CreatePostEphemeralRequest,
}
/// struct for passing parameters to the method [`delete_post`]
#[derive(Clone, Debug, Default)]
pub struct DeletePostParams {
/// ID of the post to delete
pub post_id: String,
}
/// struct for passing parameters to the method [`do_post_action`]
#[derive(Clone, Debug, Default)]
pub struct DoPostActionParams {
/// Post GUID
pub post_id: String,
/// Action GUID
pub action_id: String,
}
/// struct for passing parameters to the method [`get_file_infos_for_post`]
#[derive(Clone, Debug, Default)]
pub struct GetFileInfosForPostParams {
/// ID of the post
pub post_id: String,
/// Defines if result should include deleted posts, must have 'manage_system' (admin) permission.
pub include_deleted: Option<bool>,
}
/// struct for passing parameters to the method [`get_flagged_posts_for_user`]
#[derive(Clone, Debug, Default)]
pub struct GetFlaggedPostsForUserParams {
/// ID of the user
pub user_id: String,
/// Team ID
pub team_id: Option<String>,
/// Channel ID
pub channel_id: Option<String>,
/// The page to select
pub page: Option<i32>,
/// The number of posts per page
pub per_page: Option<i32>,
}
/// struct for passing parameters to the method [`get_post`]
#[derive(Clone, Debug, Default)]
pub struct GetPostParams {
/// ID of the post to get
pub post_id: String,
/// Defines if result should include deleted posts, must have 'manage_system' (admin) permission.
pub include_deleted: Option<bool>,
}
/// struct for passing parameters to the method [`get_post_thread`]
#[derive(Clone, Debug, Default)]
pub struct GetPostThreadParams {
/// ID of a post in the thread
pub post_id: String,
/// The number of posts per page
pub per_page: Option<i32>,
/// The post_id to return the next page of posts from
pub from_post: Option<String>,
/// The create_at timestamp to return the next page of posts from
pub from_create_at: Option<i32>,
/// The direction to return the posts. Either up or down.
pub direction: Option<String>,
/// Whether to skip fetching threads or not
pub skip_fetch_threads: Option<bool>,
/// Whether the client uses CRT or not
pub collapsed_threads: Option<bool>,
/// Whether to return the associated users as part of the response or not
pub collapsed_threads_extended: Option<bool>,
}
/// struct for passing parameters to the method [`get_posts_around_last_unread`]
#[derive(Clone, Debug, Default)]
pub struct GetPostsAroundLastUnreadParams {
/// ID of the user
pub user_id: String,
/// The channel ID to get the posts for
pub channel_id: String,
/// Number of posts before the oldest unread posts. Maximum is 200 posts if limit is set greater than that.
pub limit_before: Option<u32>,
/// Number of posts after and including the oldest unread post. Maximum is 200 posts if limit is set greater than that.
pub limit_after: Option<u32>,
/// Whether to skip fetching threads or not
pub skip_fetch_threads: Option<bool>,
/// Whether the client uses CRT or not
pub collapsed_threads: Option<bool>,
/// Whether to return the associated users as part of the response or not
pub collapsed_threads_extended: Option<bool>,
}
/// struct for passing parameters to the method [`get_posts_by_ids`]
#[derive(Clone, Debug, Default)]
pub struct GetPostsByIdsParams {
/// List of post ids
pub request_body: Vec<String>,
}
/// struct for passing parameters to the method [`get_posts_for_channel`]
#[derive(Clone, Debug, Default)]
pub struct GetPostsForChannelParams {
/// The channel ID to get the posts for
pub channel_id: String,
/// The page to select
pub page: Option<i32>,
/// The number of posts per page
pub per_page: Option<i32>,
/// Provide a non-zero value in Unix time milliseconds to select posts modified after that time
pub since: Option<i32>,
/// A post id to select the posts that came before this one
pub before: Option<String>,
/// A post id to select the posts that came after this one
pub after: Option<String>,
/// Whether to include deleted posts or not. Must have system admin permissions.
pub include_deleted: Option<bool>,
}
/// struct for passing parameters to the method [`patch_post`]
#[derive(Clone, Debug, Default)]
pub struct PatchPostParams {
/// Post GUID
pub post_id: String,
/// Post object that is to be updated
pub patch_post_request: crate::openapi::models::PatchPostRequest,
}
/// struct for passing parameters to the method [`pin_post`]
#[derive(Clone, Debug, Default)]
pub struct PinPostParams {
/// Post GUID
pub post_id: String,
}
/// struct for passing parameters to the method [`save_acknowledgement_for_post`]
#[derive(Clone, Debug, Default)]
pub struct SaveAcknowledgementForPostParams {
/// User GUID
pub user_id: String,
/// Post GUID
pub post_id: String,
}
/// struct for passing parameters to the method [`save_acknowledgement_for_post_0`]
#[derive(Clone, Debug, Default)]
pub struct SaveAcknowledgementForPost0Params {
/// User GUID
pub user_id: String,
/// Post GUID
pub post_id: String,
}
/// struct for passing parameters to the method [`search_posts`]
#[derive(Clone, Debug, Default)]
pub struct SearchPostsParams {
/// Team GUID
pub team_id: String,
/// The search terms and logic to use in the search.
pub search_posts_request: crate::openapi::models::SearchPostsRequest,
}
/// struct for passing parameters to the method [`set_post_reminder`]
#[derive(Clone, Debug, Default)]
pub struct SetPostReminderParams {
/// User GUID
pub user_id: String,
/// Post GUID
pub post_id: String,
/// Target time for the reminder
pub set_post_reminder_request: crate::openapi::models::SetPostReminderRequest,
}
/// struct for passing parameters to the method [`set_post_unread`]
#[derive(Clone, Debug, Default)]
pub struct SetPostUnreadParams {
/// User GUID
pub user_id: String,
/// Post GUID
pub post_id: String,
}
/// struct for passing parameters to the method [`unpin_post`]
#[derive(Clone, Debug, Default)]
pub struct UnpinPostParams {
/// Post GUID
pub post_id: String,
}
/// struct for passing parameters to the method [`update_post`]
#[derive(Clone, Debug, Default)]
pub struct UpdatePostParams {
/// ID of the post to update
pub post_id: String,
/// Post object that is to be updated
pub update_post_request: crate::openapi::models::UpdatePostRequest,
}
/// struct for typed errors of method [`create_post`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum CreatePostError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`create_post_ephemeral`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum CreatePostEphemeralError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_post`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum DeletePostError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`do_post_action`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum DoPostActionError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_file_infos_for_post`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum GetFileInfosForPostError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_flagged_posts_for_user`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum GetFlaggedPostsForUserError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_post`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum GetPostError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_post_thread`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum GetPostThreadError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_posts_around_last_unread`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum GetPostsAroundLastUnreadError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_posts_by_ids`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum GetPostsByIdsError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_posts_for_channel`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum GetPostsForChannelError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`patch_post`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum PatchPostError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`pin_post`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum PinPostError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`save_acknowledgement_for_post`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum SaveAcknowledgementForPostError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
Status404(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`save_acknowledgement_for_post_0`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum SaveAcknowledgementForPost0Error {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
Status404(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`search_posts`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum SearchPostsError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`set_post_reminder`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum SetPostReminderError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
Status404(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`set_post_unread`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum SetPostUnreadError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
Status404(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`unpin_post`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum UnpinPostError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`update_post`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum UpdatePostError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// 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.
pub async fn create_post(
configuration: &configuration::Configuration,
params: CreatePostParams,
) -> Result<crate::openapi::models::Post, Error<CreatePostError>> {
let local_var_configuration = configuration;
// unbox the parameters
let create_post_request = params.create_post_request;
let set_online = params.set_online;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/api/v4/posts", local_var_configuration.base_path);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_str) = set_online {
local_var_req_builder =
local_var_req_builder.query(&[("set_online", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&create_post_request);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<CreatePostError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
/// Create a new ephemeral post in a channel. ##### Permissions Must have `create_post_ephemeral` permission (currently only given to system admin)
pub async fn create_post_ephemeral(
configuration: &configuration::Configuration,
params: CreatePostEphemeralParams,
) -> Result<crate::openapi::models::Post, Error<CreatePostEphemeralError>> {
let local_var_configuration = configuration;
// unbox the parameters
let create_post_ephemeral_request = params.create_post_ephemeral_request;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/posts/ephemeral",
local_var_configuration.base_path
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&create_post_ephemeral_request);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<CreatePostEphemeralError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
/// 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.
pub async fn delete_post(
configuration: &configuration::Configuration,
params: DeletePostParams,
) -> Result<crate::openapi::models::StatusOk, Error<DeletePostError>> {
let local_var_configuration = configuration;
// unbox the parameters
let post_id = params.post_id;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/posts/{post_id}",
local_var_configuration.base_path,
post_id = super::urlencode(post_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<DeletePostError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
/// 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.
pub async fn do_post_action(
configuration: &configuration::Configuration,
params: DoPostActionParams,
) -> Result<crate::openapi::models::StatusOk, Error<DoPostActionError>> {
let local_var_configuration = configuration;
// unbox the parameters
let post_id = params.post_id;
let action_id = params.action_id;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/posts/{post_id}/actions/{action_id}",
local_var_configuration.base_path,
post_id = super::urlencode(post_id),
action_id = super::urlencode(action_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<DoPostActionError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
/// 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.
pub async fn get_file_infos_for_post(
configuration: &configuration::Configuration,
params: GetFileInfosForPostParams,
) -> Result<Vec<crate::openapi::models::FileInfo>, Error<GetFileInfosForPostError>> {
let local_var_configuration = configuration;
// unbox the parameters
let post_id = params.post_id;
let include_deleted = params.include_deleted;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/posts/{post_id}/files/info",
local_var_configuration.base_path,
post_id = super::urlencode(post_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_str) = include_deleted {
local_var_req_builder =
local_var_req_builder.query(&[("include_deleted", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetFileInfosForPostError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
/// 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.
pub async fn get_flagged_posts_for_user(
configuration: &configuration::Configuration,
params: GetFlaggedPostsForUserParams,
) -> Result<Vec<crate::openapi::models::PostList>, Error<GetFlaggedPostsForUserError>> {
let local_var_configuration = configuration;
// unbox the parameters
let user_id = params.user_id;
let team_id = params.team_id;
let channel_id = params.channel_id;
let page = params.page;
let per_page = params.per_page;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/users/{user_id}/posts/flagged",
local_var_configuration.base_path,
user_id = super::urlencode(user_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_str) = team_id {
local_var_req_builder =
local_var_req_builder.query(&[("team_id", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = channel_id {
local_var_req_builder =
local_var_req_builder.query(&[("channel_id", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = page {
local_var_req_builder =
local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = per_page {
local_var_req_builder =
local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetFlaggedPostsForUserError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
/// 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.
pub async fn get_post(
configuration: &configuration::Configuration,
params: GetPostParams,
) -> Result<crate::openapi::models::Post, Error<GetPostError>> {
let local_var_configuration = configuration;
// unbox the parameters
let post_id = params.post_id;
let include_deleted = params.include_deleted;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/posts/{post_id}",
local_var_configuration.base_path,
post_id = super::urlencode(post_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_str) = include_deleted {
local_var_req_builder =
local_var_req_builder.query(&[("include_deleted", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetPostError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
/// 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.
pub async fn get_post_thread(
configuration: &configuration::Configuration,
params: GetPostThreadParams,
) -> Result<crate::openapi::models::PostList, Error<GetPostThreadError>> {
let local_var_configuration = configuration;
// unbox the parameters
let post_id = params.post_id;
let per_page = params.per_page;
let from_post = params.from_post;
let from_create_at = params.from_create_at;
let direction = params.direction;
let skip_fetch_threads = params.skip_fetch_threads;
let collapsed_threads = params.collapsed_threads;
let collapsed_threads_extended = params.collapsed_threads_extended;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/posts/{post_id}/thread",
local_var_configuration.base_path,
post_id = super::urlencode(post_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_str) = per_page {
local_var_req_builder =
local_var_req_builder.query(&[("perPage", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = from_post {
local_var_req_builder =
local_var_req_builder.query(&[("fromPost", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = from_create_at {
local_var_req_builder =
local_var_req_builder.query(&[("fromCreateAt", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = direction {
local_var_req_builder =
local_var_req_builder.query(&[("direction", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = skip_fetch_threads {
local_var_req_builder =
local_var_req_builder.query(&[("skipFetchThreads", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = collapsed_threads {
local_var_req_builder =
local_var_req_builder.query(&[("collapsedThreads", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = collapsed_threads_extended {
local_var_req_builder = local_var_req_builder
.query(&[("collapsedThreadsExtended", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetPostThreadError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
/// 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
pub async fn get_posts_around_last_unread(
configuration: &configuration::Configuration,
params: GetPostsAroundLastUnreadParams,
) -> Result<crate::openapi::models::PostList, Error<GetPostsAroundLastUnreadError>> {
let local_var_configuration = configuration;
// unbox the parameters
let user_id = params.user_id;
let channel_id = params.channel_id;
let limit_before = params.limit_before;
let limit_after = params.limit_after;
let skip_fetch_threads = params.skip_fetch_threads;
let collapsed_threads = params.collapsed_threads;
let collapsed_threads_extended = params.collapsed_threads_extended;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/users/{user_id}/channels/{channel_id}/posts/unread",
local_var_configuration.base_path,
user_id = super::urlencode(user_id),
channel_id = super::urlencode(channel_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_str) = limit_before {
local_var_req_builder =
local_var_req_builder.query(&[("limit_before", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = limit_after {
local_var_req_builder =
local_var_req_builder.query(&[("limit_after", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = skip_fetch_threads {
local_var_req_builder =
local_var_req_builder.query(&[("skipFetchThreads", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = collapsed_threads {
local_var_req_builder =
local_var_req_builder.query(&[("collapsedThreads", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = collapsed_threads_extended {
local_var_req_builder = local_var_req_builder
.query(&[("collapsedThreadsExtended", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetPostsAroundLastUnreadError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
/// 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.
pub async fn get_posts_by_ids(
configuration: &configuration::Configuration,
params: GetPostsByIdsParams,
) -> Result<Vec<crate::openapi::models::Post>, Error<GetPostsByIdsError>> {
let local_var_configuration = configuration;
// unbox the parameters
let request_body = params.request_body;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/api/v4/posts/ids", local_var_configuration.base_path);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&request_body);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetPostsByIdsError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
/// 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.
pub async fn get_posts_for_channel(
configuration: &configuration::Configuration,
params: GetPostsForChannelParams,
) -> Result<crate::openapi::models::PostList, Error<GetPostsForChannelError>> {
let local_var_configuration = configuration;
// unbox the parameters
let channel_id = params.channel_id;
let page = params.page;
let per_page = params.per_page;
let since = params.since;
let before = params.before;
let after = params.after;
let include_deleted = params.include_deleted;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/channels/{channel_id}/posts",
local_var_configuration.base_path,
channel_id = super::urlencode(channel_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_str) = page {
local_var_req_builder =
local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = per_page {
local_var_req_builder =
local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = since {
local_var_req_builder =
local_var_req_builder.query(&[("since", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = before {
local_var_req_builder =
local_var_req_builder.query(&[("before", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = after {
local_var_req_builder =
local_var_req_builder.query(&[("after", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = include_deleted {
local_var_req_builder =
local_var_req_builder.query(&[("include_deleted", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetPostsForChannelError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
/// 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.
pub async fn patch_post(
configuration: &configuration::Configuration,
params: PatchPostParams,
) -> Result<crate::openapi::models::Post, Error<PatchPostError>> {
let local_var_configuration = configuration;
// unbox the parameters
let post_id = params.post_id;
let patch_post_request = params.patch_post_request;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/posts/{post_id}/patch",
local_var_configuration.base_path,
post_id = super::urlencode(post_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&patch_post_request);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<PatchPostError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
/// 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.
pub async fn pin_post(
configuration: &configuration::Configuration,
params: PinPostParams,
) -> Result<crate::openapi::models::StatusOk, Error<PinPostError>> {
let local_var_configuration = configuration;
// unbox the parameters
let post_id = params.post_id;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/posts/{post_id}/pin",
local_var_configuration.base_path,
post_id = super::urlencode(post_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<PinPostError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
/// Acknowledge a post that has a request for acknowledgements. ##### Permissions Must have `read_channel` permission for the channel the post is in.<br/> Must be logged in as the user or have `edit_other_users` permission. __Minimum server version__: 7.7
pub async fn save_acknowledgement_for_post(
configuration: &configuration::Configuration,
params: SaveAcknowledgementForPostParams,
) -> Result<crate::openapi::models::PostAcknowledgement, Error<SaveAcknowledgementForPostError>> {
let local_var_configuration = configuration;
// unbox the parameters
let user_id = params.user_id;
let post_id = params.post_id;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/users/{user_id}/posts/{post_id}/ack",
local_var_configuration.base_path,
user_id = super::urlencode(user_id),
post_id = super::urlencode(post_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<SaveAcknowledgementForPostError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
/// Delete an acknowledgement form a post that you had previously acknowledged. ##### Permissions Must have `read_channel` permission for the channel the post is in.<br/> Must be logged in as the user or have `edit_other_users` permission.<br/> The post must have been acknowledged in the previous 5 minutes. __Minimum server version__: 7.7
pub async fn save_acknowledgement_for_post_0(
configuration: &configuration::Configuration,
params: SaveAcknowledgementForPost0Params,
) -> Result<crate::openapi::models::StatusOk, Error<SaveAcknowledgementForPost0Error>> {
let local_var_configuration = configuration;
// unbox the parameters
let user_id = params.user_id;
let post_id = params.post_id;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/users/{user_id}/posts/{post_id}/ack",
local_var_configuration.base_path,
user_id = super::urlencode(user_id),
post_id = super::urlencode(post_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<SaveAcknowledgementForPost0Error> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
/// Search posts in the team and from the provided terms string. ##### Permissions Must be authenticated and have the `view_team` permission.
pub async fn search_posts(
configuration: &configuration::Configuration,
params: SearchPostsParams,
) -> Result<crate::openapi::models::PostListWithSearchMatches, Error<SearchPostsError>> {
let local_var_configuration = configuration;
// unbox the parameters
let team_id = params.team_id;
let search_posts_request = params.search_posts_request;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/teams/{team_id}/posts/search",
local_var_configuration.base_path,
team_id = super::urlencode(team_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&search_posts_request);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<SearchPostsError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
/// 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
pub async fn set_post_reminder(
configuration: &configuration::Configuration,
params: SetPostReminderParams,
) -> Result<crate::openapi::models::StatusOk, Error<SetPostReminderError>> {
let local_var_configuration = configuration;
// unbox the parameters
let user_id = params.user_id;
let post_id = params.post_id;
let set_post_reminder_request = params.set_post_reminder_request;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/users/{user_id}/posts/{post_id}/reminder",
local_var_configuration.base_path,
user_id = super::urlencode(user_id),
post_id = super::urlencode(post_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&set_post_reminder_request);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<SetPostReminderError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
/// 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
pub async fn set_post_unread(
configuration: &configuration::Configuration,
params: SetPostUnreadParams,
) -> Result<crate::openapi::models::ChannelUnreadAt, Error<SetPostUnreadError>> {
let local_var_configuration = configuration;
// unbox the parameters
let user_id = params.user_id;
let post_id = params.post_id;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/users/{user_id}/posts/{post_id}/set_unread",
local_var_configuration.base_path,
user_id = super::urlencode(user_id),
post_id = super::urlencode(post_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<SetPostUnreadError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
/// 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.
pub async fn unpin_post(
configuration: &configuration::Configuration,
params: UnpinPostParams,
) -> Result<crate::openapi::models::StatusOk, Error<UnpinPostError>> {
let local_var_configuration = configuration;
// unbox the parameters
let post_id = params.post_id;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/posts/{post_id}/unpin",
local_var_configuration.base_path,
post_id = super::urlencode(post_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<UnpinPostError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
/// 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.
pub async fn update_post(
configuration: &configuration::Configuration,
params: UpdatePostParams,
) -> Result<crate::openapi::models::Post, Error<UpdatePostError>> {
let local_var_configuration = configuration;
// unbox the parameters
let post_id = params.post_id;
let update_post_request = params.update_post_request;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/posts/{post_id}",
local_var_configuration.base_path,
post_id = super::urlencode(post_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&update_post_request);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<UpdatePostError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}