From 1d97b8d3f51e385666f364afcb7b66528bb9815d Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 21 Mar 2024 02:32:35 +0100 Subject: [PATCH] feat: add discoverable to actors idk if it makes a difference? ap doesnt mention it but everyone has it --- src/activitystream/macros.rs | 17 +++++++++++++++++ src/activitystream/object/actor.rs | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/src/activitystream/macros.rs b/src/activitystream/macros.rs index 7366019d..e0c800f7 100644 --- a/src/activitystream/macros.rs +++ b/src/activitystream/macros.rs @@ -100,6 +100,12 @@ macro_rules! getter { } }; + ($name:ident -> bool) => { + fn $name(&self) -> Option { + self.get(stringify!($name))?.as_bool() + } + }; + ($name:ident -> &str) => { fn $name(&self) -> Option<&str> { self.get(stringify!($name))?.as_str() @@ -185,6 +191,17 @@ macro_rules! getter { #[macro_export] macro_rules! setter { + ($name:ident -> bool) => { + paste::item! { + fn [< set_$name >](mut self, val: Option) -> Self { + $crate::activitystream::macros::set_maybe_value( + &mut self, stringify!($name), val.map(|x| serde_json::Value::Bool(x)) + ); + self + } + } + }; + ($name:ident -> &str) => { paste::item! { fn [< set_$name >](mut self, val: Option<&str>) -> Self { diff --git a/src/activitystream/object/actor.rs b/src/activitystream/object/actor.rs index b1758278..afd8c09e 100644 --- a/src/activitystream/object/actor.rs +++ b/src/activitystream/object/actor.rs @@ -24,6 +24,8 @@ pub trait Actor : super::Object { fn streams(&self) -> Node { Node::empty() } fn endpoints(&self) -> Option> { None } fn public_key(&self) -> Node { Node::empty() } + // idk about this? everyone has it but AP doesn't mention it + fn discoverable(&self) -> Option { None } } pub trait ActorMut : super::ObjectMut { @@ -37,6 +39,7 @@ pub trait ActorMut : super::ObjectMut { fn set_streams(self, val: Node) -> Self; fn set_endpoints(self, val: Option>) -> Self; fn set_public_key(self, val: Node) -> Self; + fn set_discoverable(self, val: Option) -> Self; } impl Actor for serde_json::Value { @@ -49,6 +52,7 @@ impl Actor for serde_json::Value { getter! { liked -> node impl Collection } getter! { streams -> node impl Collection } getter! { public_key::publicKey -> node impl PublicKey } + getter! { discoverable -> bool } fn endpoints(&self) -> Option> { todo!() @@ -65,6 +69,7 @@ impl ActorMut for serde_json::Value { setter! { liked -> node impl Collection } setter! { streams -> node impl Collection } setter! { public_key::publicKey -> node impl PublicKey } + setter! { discoverable -> bool } fn set_endpoints(self, _val: Option>) -> Self { todo!()