mastodon API rust lib elefren, fixed and updated. and also all ASYNC! NB. most examples are now wrong.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
elefren-fork/src/entities/status.rs

140 lines
83 KiB

//! Module containing all info relating to a status.
7 years ago
use super::prelude::*;
use crate::{
entities::{card::Card, poll::Poll},
status_builder::Visibility,
};
6 years ago
use chrono::prelude::*;
use serde::{Deserialize, Serialize};
7 years ago
/// A status from the instance.
#[derive(Debug, Clone, Deserialize, PartialEq)]
7 years ago
pub struct Status {
/// The ID of the status.
pub id: String,
/// A Fediverse-unique resource ID.
7 years ago
pub uri: String,
/// The time the status was created.
pub created_at: DateTime<Utc>,
/// The Account which posted the status.
7 years ago
pub account: Account,
/// Body of the status; this will contain HTML
/// (remote HTML already sanitized)
7 years ago
pub content: String,
/// The visibilty of the status.
pub visibility: Visibility,
/// Whether media attachments should be hidden by default.
pub sensitive: bool,
/// If not empty, warning text that should be displayed before the actual
/// content.
7 years ago
pub spoiler_text: String,
/// An array of attachments.
7 years ago
pub media_attachments: Vec<Attachment>,
/// Name of application used to post status.
pub application: Option<Application>,
/// An array of mentions.
7 years ago
pub mentions: Vec<Mention>,
/// An array of tags.
7 years ago
pub tags: Vec<Tag>,
/// An array of Emoji
pub emojis: Vec<Emoji>,
/// The number of reblogs for the status.
pub reblogs_count: u64,
/// The number of favourites for the status.
pub favourites_count: u64,
/// The numbef or replies to this status.
pub replies_count: Option<u64>,
/// URL to the status page (can be remote)
pub url: Option<String>,
/// The ID of the status this status is replying to, if the status is
/// a reply.
pub in_reply_to_id: Option<String>,
/// The ID of the account this status is replying to, if the status is
/// a reply.
pub in_reply_to_account_id: Option<String>,
/// If this status is a reblogged Status of another User.
pub reblog: Option<Box<Status>>,
/// The poll attached to the status.
pub poll: Option<Poll>,
/// The associated card
pub card: Option<Card>,
/// The detected language for the status, if detected.
pub language: Option<String>,
/// Plain-text source of a status. Returned instead of content when status is deleted, so the user may redraft from the source text without the client having to reverse-engineer the original text from the HTML content.
pub text: Option<String>,
/// Whether the application client has favourited the status.
pub favourited: Option<bool>,
/// Whether the application client has reblogged the status.
pub reblogged: Option<bool>,
/// Have you muted notifications for this status's conversation?
pub muted: Option<bool>,
/// Have you bookmarked this status?
pub bookmarked: Option<bool>,
/// Whether this is the pinned status for the account that posted it.
pub pinned: Option<bool>,
7 years ago
}
/// A mention of another user.
#[derive(Debug, Clone, Deserialize, PartialEq)]
7 years ago
pub struct Mention {
/// URL of user's profile (can be remote).
7 years ago
pub url: String,
/// The username of the account.
7 years ago
pub username: String,
/// Equals `username` for local users, includes `@domain` for remote ones.
7 years ago
pub acct: String,
/// Account ID.
pub id: String,
7 years ago
}
/// Struct representing an emoji within text.
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub struct Emoji {
/// The shortcode of the emoji
pub shortcode: String,
/// URL to the emoji static image
pub static_url: String,
/// URL to the emoji image
pub url: String,
}
/// Hashtags in the status.
#[derive(Debug, Clone, Deserialize, PartialEq)]
7 years ago
pub struct Tag {
/// The hashtag, not including the preceding `#`.
7 years ago
pub name: String,
/// The URL of the hashtag.
7 years ago
pub url: String,
/// Usage statistics for given days.
pub history: Option<Vec<History>>,
}
/// Represents daily usage history of a hashtag.
#[derive(Debug, Clone, Deserialize, PartialEq)]
pub struct History {
/// UNIX timestamp on midnight of the given day.
day: String,
/// the counted usage of the tag within that day.
uses: String,
/// the total of accounts using the tag within that day.
accounts: String,
7 years ago
}
/// Application details.
#[derive(Debug, Clone, Deserialize, PartialEq)]
7 years ago
pub struct Application {
/// Name of the application.
7 years ago
pub name: String,
/// Homepage URL of the application.
pub website: Option<String>,
7 years ago
}
#[cfg(test)]
#[test]
fn test_deser_lotta_statuses() {
let json = r#"[{"account":{"acct":"sugarbell@handholding.gay","avatar":"https://handholding.gay/files/89d379ae-d27a-4241-a5b0-2d6ec8d59d4d","avatar_static":"https://handholding.gay/files/89d379ae-d27a-4241-a5b0-2d6ec8d59d4d","bot":false,"created_at":"2021-08-04T16:25:29.000Z","display_name":"Sugarbell♡","emojis":[{"shortcode":"ablobcatheartsqueeze","static_url":"https://handholding.gay/files/7f90a0b8-17a6-493a-af52-f7a889168d61","url":"https://handholding.gay/files/7f90a0b8-17a6-493a-af52-f7a889168d61","visible_in_picker":false},{"shortcode":"blobcat3c","static_url":"https://handholding.gay/files/a0de5a33-b95c-4d34-9665-06071176e726","url":"https://handholding.gay/files/a0de5a33-b95c-4d34-9665-06071176e726","visible_in_picker":false}],"fields":[{"name":"Pronouns","value":"They/Them, She/Her"},{"name":"Languages","value":"English, German"},{"name":"Loves","value":"You!"}],"followers_count":112,"following_count":130,"fqn":"sugarbell@handholding.gay","header":"https://piggo.space/images/banner.png","header_static":"https://piggo.space/images/banner.png","id":"A9zFkAuIDcs17YggPQ","locked":true,"note":"<p></p><span> New main of </span><a href=\"https://handholding.gay/@fluff@tiny-pillowfort.floating-in.space\" class=\"u-url mention\">@fluff@tiny-pillowfort.floating-in.space</a><span><br/> ༶•┈┈⛧┈♛ ♛┈⛧┈┈•༶ <br/><br/>&quot;isi sees problem isi hugs problem. isi is a simple human&quot; - </span><a href=\"https://handholding.gay/@khaosgrille@fedi.absturztau.be\" class=\"u-url mention\">@khaosgrille@fedi.absturztau.be</a><span><br/><br/>&quot;love how isi just radiates pink energy<br/>a pink aura<br/>very pink<br/><br/>pinkpunk&quot; - </span><a href=\"https://handholding.gay/@nekojanai@pl.neko.bar\" class=\"u-url mention\">@nekojanai@pl.neko.bar</a><span><br/><br/>&quot;Isi ist wie eine Tasse Kaffee mit viel Milch und zwei Zuckerwürfeln </span>:blobcat3c:<span> &quot; - </span><a href=\"https://handholding.gay/@fristi@kartoffel.cafe\" class=\"u-url mention\">@fristi@kartoffel.cafe</a><span><br/><br/> ༶•┈┈⛧┈♛ ♛┈⛧┈┈•༶<br/><br/>Very much in love with </span><a href=\"https://handholding.gay/@steph@handholding.gay\" class=\"u-url mention\">@steph@handholding.gay</a><span> </span>:ablobcatheartsqueeze:<span> </span><p></p>","pleroma":{"accepts_chat_messages":null,"also_known_as":[],"ap_id":"https://handholding.gay/users/8p03tszdvl","background_image":null,"favicon":null,"hide_favorites":true,"hide_followers":false,"hide_followers_count":false,"hide_follows":false,"hide_follows_count":false,"is_admin":false,"is_confirmed":true,"is_moderator":false,"relationship":{},"skip_thread_containment":false,"tags":[]},"source":{"fields":[],"note":"","pleroma":{"actor_type":"Person","discoverable":true},"sensitive":false},"statuses_count":1182,"url":"https://handholding.gay/@sugarbell","username":"sugarbell"},"application":null,"bookmarked":false,"card":null,"content":"<p><a href=\"https://mk.toast.cafe/@tost\" class=\"u-url mention\">@tost@mk.toast.cafe</a><span> </span>:hugs:</p>","created_at":"2021-09-07T18:55:19.000Z","emojis":[{"shortcode":"hugs","static_url":"https://handholding.gay/files/24c88aac-8a0f-4ecb-a9df-e9f5bd626968","url":"https://handholding.gay/files/24c88aac-8a0f-4ecb-a9df-e9f5bd626968","visible_in_picker":false}],"favourited":false,"favourites_count":0,"id":"AB7wabA25wv1iSfTii","in_reply_to_account_id":"A9sWIhMKJ79km8Z3ZI","in_reply_to_id":"AB7wab4MR2NjQs0wsa","language":null,"media_attachments":[],"mentions":[{"acct":"tost@mk.toast.cafe","id":"A9sWIhMKJ79km8Z3ZI","url":"https://mk.toast.cafe/@tost","username":"tost"}],"muted":false,"pinned":false,"pleroma":{"content":{"text/plain":"@tost@mk.toast.cafe :hugs:"},"conversation_id":6554521,"direct_conversation_id":null,"emoji_reactions":[],"expires_at":null,"in_reply_to_account_acct":"tost@mk.toast.cafe","local":false,"parent_visible":true,"spoiler_text":{"text/plain":""},"thread_muted":false},"poll":null,"reblog":null,"reblogged":false,"reblogs_count":0,"replies_count":0,"sensitive":false,"spoi
let pieces : Vec<Status> = serde_json::from_str(json).unwrap();
}