From a499c93e995d83f35954ea345f3801b39c74f424 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 2 May 2024 00:29:17 +0200 Subject: [PATCH] feat(apb): add my custom extension to count follows this is really mehhh because if it was possible to embed following/followers collections this would be pointless but it isn't so to avoid making multiple fetches i'm adding these fields in the first actor document --- apb/Cargo.toml | 1 + apb/src/types/object/actor.rs | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/apb/Cargo.toml b/apb/Cargo.toml index 374d8d6c..9449d0d5 100644 --- a/apb/Cargo.toml +++ b/apb/Cargo.toml @@ -28,6 +28,7 @@ default = ["activitypub-miscellaneous-terms"] # extensions activitypub-miscellaneous-terms = [] # https://swicg.github.io/miscellany/ activitypub-counters = [] # https://ns.alemi.dev/as/counters/# +activitypub-fe = [] # https://ns.alemi.dev/as/fe/# # builtin utils orm = ["dep:sea-orm"] fetch = ["dep:reqwest"] diff --git a/apb/src/types/object/actor.rs b/apb/src/types/object/actor.rs index 214bd5b1..df01590b 100644 --- a/apb/src/types/object/actor.rs +++ b/apb/src/types/object/actor.rs @@ -26,7 +26,6 @@ pub trait Actor : Object { #[cfg(feature = "activitypub-miscellaneous-terms")] fn moved_to(&self) -> Node { Node::Empty } - #[cfg(feature = "activitypub-miscellaneous-terms")] fn manually_approves_followers(&self) -> Option { None } @@ -35,6 +34,13 @@ pub trait Actor : Object { #[cfg(feature = "activitypub-fe")] fn followed_by_me(&self) -> Option { None } + #[cfg(feature = "activitypub-counters")] + fn followers_count(&self) -> Option { None } + #[cfg(feature = "activitypub-counters")] + fn following_count(&self) -> Option { None } + #[cfg(feature = "activitypub-counters")] + fn statuses_count(&self) -> Option { None } + // idk about this? everyone has it but AP doesn't mention it fn discoverable(&self) -> Option { None } } @@ -63,6 +69,13 @@ pub trait ActorMut : ObjectMut { #[cfg(feature = "activitypub-fe")] fn set_followed_by_me(self, val: Option) -> Self; + #[cfg(feature = "activitypub-counters")] + fn set_followers_count(self, val: Option) -> Self; + #[cfg(feature = "activitypub-counters")] + fn set_following_count(self, val: Option) -> Self; + #[cfg(feature = "activitypub-counters")] + fn set_statuses_count(self, val: Option) -> Self; + fn set_discoverable(self, val: Option) -> Self; } @@ -90,6 +103,13 @@ impl Actor for serde_json::Value { #[cfg(feature = "activitypub-fe")] crate::getter! { followed_by_me::followedByMe -> bool } + #[cfg(feature = "activitypub-counters")] + crate::getter! { following_count::followingCount -> u64 } + #[cfg(feature = "activitypub-counters")] + crate::getter! { followers_count::followersCount -> u64 } + #[cfg(feature = "activitypub-counters")] + crate::getter! { statuses_count::statusesCount -> u64 } + crate::getter! { discoverable -> bool } fn endpoints(&self) -> Node<::Object> { @@ -121,6 +141,14 @@ impl ActorMut for serde_json::Value { crate::setter! { following_me::followingMe -> bool } #[cfg(feature = "activitypub-fe")] crate::setter! { followed_by_me::followedByMe -> bool } + + #[cfg(feature = "activitypub-counters")] + crate::setter! { following_count::followingCount -> u64 } + #[cfg(feature = "activitypub-counters")] + crate::setter! { followers_count::followersCount -> u64 } + #[cfg(feature = "activitypub-counters")] + crate::setter! { statuses_count::statusesCount -> u64 } + fn set_endpoints(mut self, _val: Node<::Object>) -> Self { self.as_object_mut().unwrap().insert("endpoints".to_string(), serde_json::Value::Object(serde_json::Map::default())); self