diff --git a/src/activitystream/object/document.rs b/src/activitystream/object/document.rs index d3f24715..69c9c5e9 100644 --- a/src/activitystream/object/document.rs +++ b/src/activitystream/object/document.rs @@ -1,4 +1,4 @@ -use crate::strenum; +use crate::{getter, setter, strenum}; strenum! { pub enum DocumentType { @@ -18,7 +18,16 @@ pub trait DocumentMut : super::ObjectMut { fn set_document_type(self, val: Option) -> Self; } -pub trait Image : Document {} -impl Document for serde_json::Value {} +impl Document for serde_json::Value { + getter! { document_type -> type DocumentType } +} + +impl DocumentMut for serde_json::Value { + setter! { document_type -> type DocumentType } +} + + + +pub trait Image : Document {} impl Image for serde_json::Value {} diff --git a/src/activitystream/object/mod.rs b/src/activitystream/object/mod.rs index dc6c98d6..3e053f6b 100644 --- a/src/activitystream/object/mod.rs +++ b/src/activitystream/object/mod.rs @@ -55,7 +55,7 @@ pub trait Object : super::Base { fn summary(&self) -> Option<&str> { None } fn tag(&self) -> Node { Node::Empty:: } fn updated(&self) -> Option> { None } - fn url(&self) -> Option> { None::> } + fn url(&self) -> Node { Node::empty() } fn to(&self) -> Node { Node::Empty:: } fn bto(&self) -> Node { Node::Empty:: } fn cc(&self) -> Node { Node::Empty:: } @@ -85,7 +85,7 @@ pub trait ObjectMut : super::BaseMut { fn set_summary(self, val: Option<&str>) -> Self; fn set_tag(self, val: Node) -> Self; fn set_updated(self, val: Option>) -> Self; - fn set_url(self, val: Option>) -> Self; + fn set_url(self, val: Node) -> Self; fn set_to(self, val: Node) -> Self; fn set_bto(self, val: Node) -> Self; fn set_cc(self, val: Node) -> Self; @@ -122,16 +122,7 @@ impl Object for serde_json::Value { getter! { bcc -> node impl Link } getter! { media_type -> &str } getter! { duration -> &str } - - fn url(&self) -> Option> { - Some( - self.get("url")? - .as_array()? - .iter() - .filter_map(|x| Some(x.as_str()?.to_string())) - .collect() - ) - } + getter! { url -> node impl super::Link } } impl ObjectMut for serde_json::Value { @@ -161,8 +152,6 @@ impl ObjectMut for serde_json::Value { setter! { bcc -> node impl Link } setter! { media_type -> &str } setter! { duration -> &str } + setter! { url -> node impl super::Link } - fn set_url(self, _val: Option>) -> Self { - todo!() - } } diff --git a/src/model/user.rs b/src/model/user.rs index cc953656..950d4469 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -1,4 +1,5 @@ use sea_orm::entity::prelude::*; +use crate::activitystream::object::document::DocumentType; use crate::activitystream::prelude::*; use crate::{activitypub, activitystream::{object::actor::ActorType, BaseType, Node, ObjectType}}; @@ -98,14 +99,22 @@ impl crate::activitystream::object::Object for Model { fn icon(&self) -> Node { match &self.icon { - Some(x) => Node::link(x.to_string()), + Some(x) => Node::object( + crate::activitystream::raw_object() + .set_document_type(Some(DocumentType::Image)) + .set_url(Node::link(x.clone())) + ), None => Node::Empty, } } fn image(&self) -> Node { match &self.image { - Some(x) => Node::link(x.to_string()), + Some(x) => Node::object( + crate::activitystream::raw_object() + .set_document_type(Some(DocumentType::Image)) + .set_url(Node::link(x.clone())) + ), None => Node::Empty, } }