From 34c01dd858f9ae052d70bfef73308ed44913711e Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 23 May 2024 23:45:48 +0200 Subject: [PATCH] feat(apb): ostatus conversation and toot discoverable --- apb/Cargo.toml | 2 ++ apb/src/types/object/actor.rs | 8 ++++++-- apb/src/types/object/mod.rs | 24 +++++++++++++----------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/apb/Cargo.toml b/apb/Cargo.toml index 1618763..d37b0b5 100644 --- a/apb/Cargo.toml +++ b/apb/Cargo.toml @@ -29,6 +29,8 @@ default = ["activitypub-miscellaneous-terms", "send"] activitypub-miscellaneous-terms = [] # https://swicg.github.io/miscellany/ activitypub-counters = [] # https://ns.alemi.dev/as/counters/# activitypub-fe = [] # https://ns.alemi.dev/as/fe/# +ostatus = [] # https://ostatus.org# , but it redirects and 403??? just need this for conversation +toot = [] # http://joinmastodon.org/ns# , mastodon is weird tho?? litepub = [] # incomplete, https://litepub.social/ # builtin utils send = [] diff --git a/apb/src/types/object/actor.rs b/apb/src/types/object/actor.rs index abbc4dd..9bd8757 100644 --- a/apb/src/types/object/actor.rs +++ b/apb/src/types/object/actor.rs @@ -42,7 +42,7 @@ pub trait Actor : Object { #[cfg(feature = "activitypub-counters")] fn statuses_count(&self) -> Option { None } - // idk about this? everyone has it but AP doesn't mention it + #[cfg(feature = "toot")] fn discoverable(&self) -> Option { None } } @@ -93,6 +93,7 @@ pub trait ActorMut : ObjectMut { #[cfg(feature = "activitypub-counters")] fn set_statuses_count(self, val: Option) -> Self; + #[cfg(feature = "toot")] fn set_discoverable(self, val: Option) -> Self; } @@ -144,6 +145,7 @@ impl Actor for serde_json::Value { #[cfg(feature = "activitypub-counters")] crate::getter! { statuses_count::statusesCount -> u64 } + #[cfg(feature = "toot")] crate::getter! { discoverable -> bool } } @@ -172,7 +174,6 @@ impl ActorMut for serde_json::Value { crate::setter! { streams -> node Self::Collection } crate::setter! { public_key::publicKey -> node Self::PublicKey } crate::setter! { endpoints -> node Self::Endpoints } - crate::setter! { discoverable -> bool } #[cfg(feature = "activitypub-miscellaneous-terms")] crate::setter! { moved_to::movedTo -> node Self::Actor } @@ -190,6 +191,9 @@ impl ActorMut for serde_json::Value { crate::setter! { followers_count::followersCount -> u64 } #[cfg(feature = "activitypub-counters")] crate::setter! { statuses_count::statusesCount -> u64 } + + #[cfg(feature = "toot")] + crate::setter! { discoverable -> bool } } #[cfg(feature = "unstructured")] diff --git a/apb/src/types/object/mod.rs b/apb/src/types/object/mod.rs index d439c5d..749f99c 100644 --- a/apb/src/types/object/mod.rs +++ b/apb/src/types/object/mod.rs @@ -78,6 +78,9 @@ pub trait Object : Base { #[cfg(feature = "activitypub-fe")] fn liked_by_me(&self) -> Option { None } + #[cfg(feature = "ostatus")] + fn conversation(&self) -> Node { Node::Empty } + fn as_activity(&self) -> Option<&Self::Activity> { None } fn as_actor(&self) -> Option<&Self::Actor> { None } fn as_collection(&self) -> Option<&Self::Collection> { None } @@ -128,6 +131,9 @@ pub trait ObjectMut : BaseMut { #[cfg(feature = "activitypub-fe")] fn set_liked_by_me(self, val: Option) -> Self; + + #[cfg(feature = "ostatus")] + fn set_conversation(self, val: Node) -> Self; } #[cfg(feature = "unstructured")] @@ -144,6 +150,7 @@ impl Object for serde_json::Value { crate::getter! { attributed_to::attributedTo -> node Self::Actor } crate::getter! { audience -> node Self::Actor } crate::getter! { content -> &str } + crate::getter! { context -> node ::Object } crate::getter! { name -> &str } crate::getter! { end_time::endTime -> chrono::DateTime } crate::getter! { generator -> node Self::Actor } @@ -176,16 +183,8 @@ impl Object for serde_json::Value { #[cfg(feature = "activitypub-fe")] crate::getter! { liked_by_me::likedByMe -> bool } - // TODO Mastodon doesn't use a "context" field on the object but makes up a new one!! - fn context(&self) -> Node<::Object> { - match self.get("context") { - Some(x) => Node::from(x.clone()), - None => match self.get("conversation") { - Some(x) => Node::from(x.clone()), - None => Node::Empty, - } - } - } + #[cfg(feature = "ostatus")] + crate::getter! { conversation -> node ::Object } fn as_activity(&self) -> Option<&Self::Activity> { match self.object_type() { @@ -229,6 +228,7 @@ impl ObjectMut for serde_json::Value { crate::setter! { attributed_to::attributedTo -> node Self::Actor } crate::setter! { audience -> node Self::Actor } crate::setter! { content -> &str } + crate::setter! { context -> node ::Object } crate::setter! { name -> &str } crate::setter! { end_time::endTime -> chrono::DateTime } crate::setter! { generator -> node Self::Actor } @@ -252,7 +252,6 @@ impl ObjectMut for serde_json::Value { crate::setter! { media_type::mediaType -> &str } crate::setter! { duration -> &str } crate::setter! { url -> node Self::Link } - crate::setter! { context -> node ::Object } #[cfg(feature = "activitypub-miscellaneous-terms")] crate::setter! { sensitive -> bool } @@ -261,4 +260,7 @@ impl ObjectMut for serde_json::Value { #[cfg(feature = "activitypub-fe")] crate::setter! { liked_by_me::likedByMe -> bool } + + #[cfg(feature = "ostatus")] + crate::setter! { conversation -> node ::Object } }