mastodon_api\methods\builders/
status.rs

1use crate::MastodonClient;
2use crate::error::Result;
3use crate::methods::statuses::CreateStatusParams;
4use crate::models::Status;
5
6/// A builder for creating a new status.
7pub struct StatusBuilder<'a> {
8    client: &'a MastodonClient,
9    params: CreateStatusParams,
10}
11
12impl<'a> StatusBuilder<'a> {
13    pub fn new(client: &'a MastodonClient, text: &str) -> Self {
14        Self {
15            client,
16            params: CreateStatusParams {
17                status: text.to_string(),
18                in_reply_to_id: None,
19                sensitive: false,
20                spoiler_text: None,
21                visibility: None,
22                language: None,
23            },
24        }
25    }
26
27    /// ID of the status being replied to.
28    pub fn in_reply_to_id(mut self, value: &str) -> Self {
29        self.params.in_reply_to_id = Some(value.to_string());
30        self
31    }
32
33    /// Mark the status as sensitive.
34    pub fn sensitive(mut self, value: bool) -> Self {
35        self.params.sensitive = value;
36        self
37    }
38
39    /// Text warning before the content.
40    pub fn spoiler_text(mut self, value: &str) -> Self {
41        self.params.spoiler_text = Some(value.to_string());
42        self
43    }
44
45    /// Visibility of the status ("public", "unlisted", "private", "direct").
46    pub fn visibility(mut self, value: &str) -> Self {
47        self.params.visibility = Some(value.to_string());
48        self
49    }
50
51    /// ISO 639 language code.
52    pub fn language(mut self, value: &str) -> Self {
53        self.params.language = Some(value.to_string());
54        self
55    }
56
57    /// Executes the request to create the status.
58    pub async fn send(self) -> Result<Status> {
59        self.client.statuses().create(&self.params).await
60    }
61}