Compare commits
3 commits
8e9695c1d5
...
9d2996dece
Author | SHA1 | Date | |
---|---|---|---|
9d2996dece | |||
bad86f5bcf | |||
1d01a1cbf9 |
3 changed files with 21 additions and 5 deletions
|
@ -1,9 +1,13 @@
|
||||||
/// ActivityPub object node, representing either nothing, something, a link to something or
|
/// ActivityPub object node, representing either nothing, something, a link to something or
|
||||||
/// multiple things
|
/// multiple things
|
||||||
pub enum Node<T : super::Base> {
|
pub enum Node<T : super::Base> {
|
||||||
|
/// this document node holds multiple objects
|
||||||
Array(std::collections::VecDeque<Node<T>>), // TODO would be cool to make it Box<[T]> so that Node is just a ptr
|
Array(std::collections::VecDeque<Node<T>>), // TODO would be cool to make it Box<[T]> so that Node is just a ptr
|
||||||
|
/// this document node holds one object
|
||||||
Object(Box<T>),
|
Object(Box<T>),
|
||||||
|
/// this document node holds a reference to an object
|
||||||
Link(Box<dyn crate::Link + Sync + Send>), // TODO feature flag to toggle these maybe?
|
Link(Box<dyn crate::Link + Sync + Send>), // TODO feature flag to toggle these maybe?
|
||||||
|
/// this document node is not present
|
||||||
Empty,
|
Empty,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,6 +127,9 @@ pub trait Object : Base {
|
||||||
fn as_actor(&self) -> Result<&Self::Actor, FieldErr> { Err(FieldErr("type")) }
|
fn as_actor(&self) -> Result<&Self::Actor, FieldErr> { Err(FieldErr("type")) }
|
||||||
fn as_collection(&self) -> Result<&Self::Collection, FieldErr> { Err(FieldErr("type")) }
|
fn as_collection(&self) -> Result<&Self::Collection, FieldErr> { Err(FieldErr("type")) }
|
||||||
fn as_document(&self) -> Result<&Self::Document, FieldErr> { Err(FieldErr("type")) }
|
fn as_document(&self) -> Result<&Self::Document, FieldErr> { Err(FieldErr("type")) }
|
||||||
|
|
||||||
|
#[cfg(feature = "did-core")] // TODO this isn't from did-core actually!?!?!?!?!
|
||||||
|
fn value(&self) -> Field<&str> { Err(FieldErr("value")) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ObjectMut : BaseMut {
|
pub trait ObjectMut : BaseMut {
|
||||||
|
@ -176,6 +179,9 @@ pub trait ObjectMut : BaseMut {
|
||||||
|
|
||||||
#[cfg(feature = "ostatus")]
|
#[cfg(feature = "ostatus")]
|
||||||
fn set_conversation(self, val: Node<Self::Object>) -> Self;
|
fn set_conversation(self, val: Node<Self::Object>) -> Self;
|
||||||
|
|
||||||
|
#[cfg(feature = "did-core")] // TODO this isn't from did-core actually!?!?!?!?!
|
||||||
|
fn set_value(self, val: Option<&str>) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstructured")]
|
#[cfg(feature = "unstructured")]
|
||||||
|
@ -228,6 +234,9 @@ impl Object for serde_json::Value {
|
||||||
#[cfg(feature = "ostatus")]
|
#[cfg(feature = "ostatus")]
|
||||||
crate::getter! { conversation -> node <Self as Object>::Object }
|
crate::getter! { conversation -> node <Self as Object>::Object }
|
||||||
|
|
||||||
|
#[cfg(feature = "did-core")] // TODO this isn't from did-core actually!?!?!?!?!
|
||||||
|
crate::getter! { value -> &str }
|
||||||
|
|
||||||
fn as_activity(&self) -> Result<&Self::Activity, FieldErr> {
|
fn as_activity(&self) -> Result<&Self::Activity, FieldErr> {
|
||||||
match self.object_type()? {
|
match self.object_type()? {
|
||||||
ObjectType::Activity(_) => Ok(self),
|
ObjectType::Activity(_) => Ok(self),
|
||||||
|
@ -305,4 +314,7 @@ impl ObjectMut for serde_json::Value {
|
||||||
|
|
||||||
#[cfg(feature = "ostatus")]
|
#[cfg(feature = "ostatus")]
|
||||||
crate::setter! { conversation -> node <Self as Object>::Object }
|
crate::setter! { conversation -> node <Self as Object>::Object }
|
||||||
|
|
||||||
|
#[cfg(feature = "did-core")] // TODO this isn't from did-core actually!?!?!?!?!
|
||||||
|
crate::setter! { value -> &str }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use sea_orm::{entity::prelude::*, QuerySelect, SelectColumns};
|
use sea_orm::{entity::prelude::*, QuerySelect, SelectColumns};
|
||||||
|
|
||||||
use apb::{ActorMut, ActorType, BaseMut, DocumentMut, EndpointsMut, ObjectMut, PublicKeyMut};
|
use apb::{field::OptionalString, ActorMut, ActorType, BaseMut, DocumentMut, EndpointsMut, ObjectMut, PublicKeyMut};
|
||||||
|
|
||||||
use crate::ext::{JsonVec, TypeName};
|
use crate::ext::{JsonVec, TypeName};
|
||||||
|
|
||||||
|
@ -22,11 +22,11 @@ impl TypeName for Field {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<serde_json::Value> for Field {
|
impl<T: apb::Object> From<T> for Field {
|
||||||
fn from(value: serde_json::Value) -> Self {
|
fn from(value: T) -> Self {
|
||||||
Field {
|
Field {
|
||||||
name: value.get("name").and_then(|x| x.as_str()).unwrap_or_default().to_string(),
|
name: value.name().str().unwrap_or_default(),
|
||||||
value: value.get("value").and_then(|x| x.as_str()).unwrap_or_default().to_string(),
|
value: value.value().str().unwrap_or_default(),
|
||||||
field_type: "PropertyValue".to_string(), // TODO can we try parsing this instead??
|
field_type: "PropertyValue".to_string(), // TODO can we try parsing this instead??
|
||||||
verified_at: None, // TODO where does verified_at come from? extend apb maybe
|
verified_at: None, // TODO where does verified_at come from? extend apb maybe
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue