fix: image and icon are inline anonymous objects..

This commit is contained in:
əlemi 2024-03-21 02:32:13 +01:00
parent de9c3498bc
commit b27c2cf31a
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 27 additions and 20 deletions

View file

@ -1,4 +1,4 @@
use crate::strenum; use crate::{getter, setter, strenum};
strenum! { strenum! {
pub enum DocumentType { pub enum DocumentType {
@ -18,7 +18,16 @@ pub trait DocumentMut : super::ObjectMut {
fn set_document_type(self, val: Option<DocumentType>) -> Self; fn set_document_type(self, val: Option<DocumentType>) -> 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 {} impl Image for serde_json::Value {}

View file

@ -55,7 +55,7 @@ pub trait Object : super::Base {
fn summary(&self) -> Option<&str> { None } fn summary(&self) -> Option<&str> { None }
fn tag(&self) -> Node<impl Object> { Node::Empty::<serde_json::Value> } fn tag(&self) -> Node<impl Object> { Node::Empty::<serde_json::Value> }
fn updated(&self) -> Option<chrono::DateTime<chrono::Utc>> { None } fn updated(&self) -> Option<chrono::DateTime<chrono::Utc>> { None }
fn url(&self) -> Option<Vec<impl super::Link>> { None::<Vec<serde_json::Value>> } fn url(&self) -> Node<impl super::Link> { Node::empty() }
fn to(&self) -> Node<impl Link> { Node::Empty::<serde_json::Value> } fn to(&self) -> Node<impl Link> { Node::Empty::<serde_json::Value> }
fn bto(&self) -> Node<impl Link> { Node::Empty::<serde_json::Value> } fn bto(&self) -> Node<impl Link> { Node::Empty::<serde_json::Value> }
fn cc(&self) -> Node<impl Link> { Node::Empty::<serde_json::Value> } fn cc(&self) -> Node<impl Link> { Node::Empty::<serde_json::Value> }
@ -85,7 +85,7 @@ pub trait ObjectMut : super::BaseMut {
fn set_summary(self, val: Option<&str>) -> Self; fn set_summary(self, val: Option<&str>) -> Self;
fn set_tag(self, val: Node<impl Object>) -> Self; fn set_tag(self, val: Node<impl Object>) -> Self;
fn set_updated(self, val: Option<chrono::DateTime<chrono::Utc>>) -> Self; fn set_updated(self, val: Option<chrono::DateTime<chrono::Utc>>) -> Self;
fn set_url(self, val: Option<Vec<impl super::Link>>) -> Self; fn set_url(self, val: Node<impl super::Link>) -> Self;
fn set_to(self, val: Node<impl Link>) -> Self; fn set_to(self, val: Node<impl Link>) -> Self;
fn set_bto(self, val: Node<impl Link>) -> Self; fn set_bto(self, val: Node<impl Link>) -> Self;
fn set_cc(self, val: Node<impl Link>) -> Self; fn set_cc(self, val: Node<impl Link>) -> Self;
@ -122,16 +122,7 @@ impl Object for serde_json::Value {
getter! { bcc -> node impl Link } getter! { bcc -> node impl Link }
getter! { media_type -> &str } getter! { media_type -> &str }
getter! { duration -> &str } getter! { duration -> &str }
getter! { url -> node impl super::Link }
fn url(&self) -> Option<Vec<impl super::Link>> {
Some(
self.get("url")?
.as_array()?
.iter()
.filter_map(|x| Some(x.as_str()?.to_string()))
.collect()
)
}
} }
impl ObjectMut for serde_json::Value { impl ObjectMut for serde_json::Value {
@ -161,8 +152,6 @@ impl ObjectMut for serde_json::Value {
setter! { bcc -> node impl Link } setter! { bcc -> node impl Link }
setter! { media_type -> &str } setter! { media_type -> &str }
setter! { duration -> &str } setter! { duration -> &str }
setter! { url -> node impl super::Link }
fn set_url(self, _val: Option<Vec<impl super::Link>>) -> Self {
todo!()
}
} }

View file

@ -1,4 +1,5 @@
use sea_orm::entity::prelude::*; use sea_orm::entity::prelude::*;
use crate::activitystream::object::document::DocumentType;
use crate::activitystream::prelude::*; use crate::activitystream::prelude::*;
use crate::{activitypub, activitystream::{object::actor::ActorType, BaseType, Node, ObjectType}}; 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<impl Image> { fn icon(&self) -> Node<impl Image> {
match &self.icon { 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, None => Node::Empty,
} }
} }
fn image(&self) -> Node<impl Image> { fn image(&self) -> Node<impl Image> {
match &self.image { 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, None => Node::Empty,
} }
} }