65 lines
1.9 KiB
Rust
65 lines
1.9 KiB
Rust
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<String>,
|
|
pub context: Option<String>,
|
|
pub published_at: Option<String>,
|
|
pub author: Actor,
|
|
pub to: Vec<Actor>,
|
|
pub url: Option<String>,
|
|
pub conversation: Option<String>,
|
|
}
|
|
|
|
#[async_trait]
|
|
impl ExpandLD<Note> for Note {
|
|
async fn expand(obj: &ObjectLD) -> Result<Note, ExpandError> {
|
|
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<ObjectLD> 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(),
|
|
}
|
|
}
|
|
}
|