mastodon_async_entities/
status.rs

1//! Module containing all info relating to a status.
2
3use std::fmt::Display;
4
5use super::prelude::*;
6use crate::{card::Card, visibility::Visibility};
7use serde::{Deserialize, Serialize};
8use time::{serde::iso8601, OffsetDateTime};
9
10/// A status from the instance.
11#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
12pub struct Status {
13    /// The ID of the status.
14    pub id: StatusId,
15    /// A Fediverse-unique resource ID.
16    pub uri: String,
17    /// URL to the status page (can be remote)
18    pub url: Option<String>,
19    /// The Account which posted the status.
20    pub account: Account,
21    /// The ID of the status this status is replying to, if the status is
22    /// a reply.
23    pub in_reply_to_id: Option<String>,
24    /// The ID of the account this status is replying to, if the status is
25    /// a reply.
26    pub in_reply_to_account_id: Option<String>,
27    /// If this status is a reblogged Status of another User.
28    pub reblog: Option<Box<Status>>,
29    /// Body of the status; this will contain HTML
30    /// (remote HTML already sanitized)
31    pub content: String,
32    /// The time the status was created.
33    #[serde(with = "iso8601")]
34    pub created_at: OffsetDateTime,
35    /// An array of Emoji
36    pub emojis: Vec<Emoji>,
37    /// The numbef or replies to this status.
38    pub replies_count: Option<u64>,
39    /// The number of reblogs for the status.
40    pub reblogs_count: u64,
41    /// The number of favourites for the status.
42    pub favourites_count: u64,
43    /// Whether the application client has reblogged the status.
44    pub reblogged: Option<bool>,
45    /// Whether the application client has favourited the status.
46    pub favourited: Option<bool>,
47    /// Whether media attachments should be hidden by default.
48    pub sensitive: bool,
49    /// If not empty, warning text that should be displayed before the actual
50    /// content.
51    pub spoiler_text: String,
52    /// The visibilty of the status.
53    pub visibility: Visibility,
54    /// An array of attachments.
55    pub media_attachments: Vec<Attachment>,
56    /// An array of mentions.
57    pub mentions: Vec<Mention>,
58    /// An array of tags.
59    pub tags: Vec<Tag>,
60    /// The associated card
61    pub card: Option<Card>,
62    /// Name of application used to post status.
63    pub application: Option<Application>,
64    /// The detected language for the status, if detected.
65    pub language: Option<String>,
66    /// Whether this is the pinned status for the account that posted it.
67    pub pinned: Option<bool>,
68}
69
70/// Wrapper type for a status ID string
71#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
72#[serde(transparent)]
73pub struct StatusId(String);
74
75impl AsRef<str> for StatusId {
76    fn as_ref(&self) -> &str {
77        &self.0
78    }
79}
80
81impl StatusId {
82    pub fn new(value: impl Into<String>) -> Self {
83        Self(value.into())
84    }
85}
86
87impl Display for StatusId {
88    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
89        write!(f, "{}", self.0)
90    }
91}
92
93static_assertions::assert_not_impl_any!(
94    StatusId: PartialEq<crate::account::AccountId>,
95    PartialEq<crate::attachment::AttachmentId>,
96    PartialEq<crate::filter::FilterId>,
97    PartialEq<crate::push::SubscriptionId>,
98    PartialEq<crate::mention::MentionId>,
99    PartialEq<crate::notification::NotificationId>,
100    PartialEq<crate::relationship::RelationshipId>,
101    PartialEq<crate::report::ReportId>,
102    PartialEq<crate::list::ListId>,
103);
104
105/// A mention of another user.
106#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
107pub struct Mention {
108    /// URL of user's profile (can be remote).
109    pub url: String,
110    /// The username of the account.
111    pub username: String,
112    /// Equals `username` for local users, includes `@domain` for remote ones.
113    pub acct: String,
114    /// Account ID.
115    pub id: String,
116}
117
118/// Struct representing an emoji within text.
119#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
120pub struct Emoji {
121    /// The shortcode of the emoji
122    pub shortcode: String,
123    /// URL to the emoji static image
124    pub static_url: String,
125    /// URL to the emoji image
126    pub url: String,
127}
128
129/// Hashtags in the status. This functions both as a
130/// [`Status::Tag`](https://docs.joinmastodon.org/entities/Status/#Tag), and
131/// as a [`Tag`](https://docs.joinmastodon.org/entities/Tag/). In the case of
132/// the former, at the time of writing, the history field is always empty and
133/// the following field is always none.
134#[allow(clippy::derive_partial_eq_without_eq)]
135#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
136pub struct Tag {
137    /// The hashtag, not including the preceding `#`.
138    pub name: String,
139    /// The URL of the hashtag.
140    pub url: String,
141    /// Usage statistics for given days (typically the past week).
142    #[serde(default = "Vec::new")]
143    pub history: Vec<TagHistory>,
144    /// Whether the current token’s authorized user is following this tag.
145    pub following: Option<bool>,
146}
147
148/// Application details.
149#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
150pub struct Application {
151    /// Name of the application.
152    pub name: String,
153    /// Homepage URL of the application.
154    pub website: Option<String>,
155}
156
157/// Usage statistics for given days (typically the past week).
158#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
159pub struct TagHistory {
160    /// UNIX timestamp on midnight of the given day.
161    pub day: String,
162    /// The counted usage of the tag within that day.
163    pub uses: String,
164    /// The total of accounts using the tag within that day.
165    pub accounts: String,
166}