use async_trait::async_trait; use super::{ context::{self, Context}, resolve, ActivityKind, Actor, ExpandError, ExpandLD, ObjectLD, }; #[derive(Debug, Clone)] pub struct Note { pub id: String, pub content: Option, pub context: Option, pub published_at: Option, pub author: Actor, pub to: Vec, pub url: Option, pub conversation: Option, } #[async_trait] impl ExpandLD for Note { async fn expand(obj: &ObjectLD) -> Result { let obj = obj.clone(); let resolver = resolve::Resolver::new(); if let Some(kind) = obj.kind { if let ActivityKind::Note = kind { Ok(Note { id: obj.id, content: obj.content, published_at: obj.published, author: obj .attributed_to .map(|id| Actor { id }) .ok_or(ExpandError::NoAttribution)?, to: obj.to_uris.into_iter().map(|id| Actor { id }).collect(), url: obj.url, context: obj.context, conversation: obj.conversation, }) } else { Err(ExpandError::InvalidKind(Some(kind))) } } else { Err(ExpandError::InvalidKind(None)) } } } impl Into for Note { fn into(self) -> ObjectLD { ObjectLD { context_uri: Some(context::CONTEXT_ID.to_string()), id: self.id.clone(), kind: Some(ActivityKind::Note), attributed_to: Some(self.author.id), published: self.published_at, content: self.content, context: self.context, conversation: self.conversation, url: Some(self.id), to_uris: self.to.into_iter().map(|a| a.id).collect(), } } }