use async_trait::async_trait; use flabk_derive::IRI; use serde::{Deserialize, Serialize}; use serde_ext::IriPartial; use self::{ context::Context, note::Note, resolve::ResolveError, serde_ext::{expand_partial, pull_single_into_vec}, }; pub mod context; pub mod note; pub mod resolve; mod serde_ext; #[derive(Clone, Copy, Serialize, Deserialize, Debug)] pub enum ActivityKind { Create, Like, Note, } #[derive(Debug, Clone)] pub enum ExpandError { InvalidKind(Option), NoAttribution, ResolveIRI(String), Other(String), } impl From for ExpandError { fn from(err: ResolveError) -> Self { Self::ResolveIRI(err.0) } } #[async_trait] pub trait ExpandLD { async fn expand(obj: &ObjectLD) -> Result; } #[derive(Clone, Serialize, Deserialize)] pub struct ActivityLD { #[serde(rename = "@context")] pub context_uri: String, pub kind: ActivityKind, #[serde(rename = "actor")] pub actor_uri: String, #[serde(rename = "to")] pub to_uris: Vec, pub object: Option, } #[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Activity { // #[serde(rename = "@context")] // #[serde(deserialize_with = "expand_partial")] // pub ap_context: Context, pub id: String, #[serde(rename = "type")] pub kind: ActivityKind, #[serde(deserialize_with = "expand_partial")] pub attributed_to: Actor, pub content: Option, pub context: Option, #[serde(deserialize_with = "pull_single_into_vec")] pub to: Vec, pub url: Option, } #[derive(Clone, Serialize, Deserialize, Debug)] pub struct ObjectLD { #[serde(rename = "@context")] pub context_uri: Option, pub id: String, #[serde(rename = "type")] pub kind: Option, #[serde(rename = "attributedTo")] pub attributed_to: Option, pub published: Option, pub content: Option, pub context: Option, pub conversation: Option, pub url: Option, #[serde(rename = "to")] #[serde(deserialize_with = "pull_single_into_vec")] pub to_uris: Vec, } pub enum ActorType {} #[derive(Debug, Clone, Deserialize, IRI, Default)] pub struct Actor { id: String, } pub async fn test() { let obj = r#"{ "@context": "https://www.w3.org/ns/activitystreams", "attributedTo": "http://localhost:3001/u/test", "content": "honk donk", "context": "data:,electrichonkytonk-2jqQ42HyJXctnBKTy1", "conversation": "data:,electrichonkytonk-2jqQ42HyJXctnBKTy1", "id": "htts://localhost:3001/u/test/h/6Q8BFF8W6PZT2ddngZ", "published": "2022-09-30T19:04:45Z", "summary": "", "to": "https://www.w3.org/ns/activitystreams#Public", "type": "Note", "url": "https://localhost/u/test/h/6Q8BFF8W6PZT2ddngZ" }"#; let obj = serde_json::from_str::(obj).unwrap(); println!(); println!("{:#?}", obj); }