#![allow(clippy::large_enum_variant)] use std::collections::HashMap; pub type SsbHash = String; pub type SsbId = String; #[derive(Debug, Serialize, Deserialize)] pub struct Mention { pub link: SsbId, pub name: Option, } #[derive(Debug, Serialize, Deserialize)] pub struct Post { #[serde(rename = "type")] pub xtype: String, pub text: String, pub mentions: Option>, } impl Post { pub fn new(text: String, mentions: Option>) -> Self { Post { xtype: String::from("post"), text, mentions, } } pub fn to_msg(&self) -> serde_json::Result { serde_json::to_value(self) } } #[derive(Debug, Deserialize)] pub struct PubAddress { pub host: Option, pub port: u16, pub key: String, } #[derive(Debug, Deserialize)] #[serde(untagged)] pub enum VoteValue { Numeric(i64), Boolean(bool), } #[derive(Debug, Deserialize)] pub struct Vote { link: SsbHash, value: VoteValue, expression: Option, } #[derive(Debug, Deserialize)] #[serde(untagged)] pub enum Image { OnlyLink(SsbHash), Complete { link: SsbHash, name: Option, size: u64, width: Option, height: Option, #[serde(rename = "type")] content_type: String, }, } #[derive(Debug, Deserialize)] pub struct DateTime { epoch: u64, tz: String, } #[derive(Debug, Deserialize)] #[serde(untagged)] pub enum Branch { One(SsbHash), Many(Vec), } #[derive(Debug, Deserialize)] #[serde(untagged)] pub enum Mentions { Link(SsbHash), One(Mention), Vector(Vec), Map(HashMap), } #[derive(Debug, Deserialize)] #[serde(tag = "type")] pub enum FeedTypedContent { #[serde(rename = "pub")] Pub { address: Option }, #[serde(rename = "post")] Post, #[serde(rename = "contact")] Contact { contact: Option, blocking: Option, following: Option, autofollow: Option, }, #[serde(rename = "about")] About { about: SsbId, name: Option, title: Option, branch: Option, image: Option, description: Option, location: Option, #[serde(rename = "startDateTime")] start_datetime: Option, }, #[serde(rename = "channel")] Channel { channel: String, subscribed: bool }, #[serde(rename = "vote")] Vote { vote: Vote }, }