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
This commit is contained in:
əlemi 2024-05-02 00:29:17 +02:00
parent a1d1ba3744
commit a499c93e99
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 30 additions and 1 deletions

View file

@ -28,6 +28,7 @@ default = ["activitypub-miscellaneous-terms"]
# extensions # extensions
activitypub-miscellaneous-terms = [] # https://swicg.github.io/miscellany/ activitypub-miscellaneous-terms = [] # https://swicg.github.io/miscellany/
activitypub-counters = [] # https://ns.alemi.dev/as/counters/# activitypub-counters = [] # https://ns.alemi.dev/as/counters/#
activitypub-fe = [] # https://ns.alemi.dev/as/fe/#
# builtin utils # builtin utils
orm = ["dep:sea-orm"] orm = ["dep:sea-orm"]
fetch = ["dep:reqwest"] fetch = ["dep:reqwest"]

View file

@ -26,7 +26,6 @@ pub trait Actor : Object {
#[cfg(feature = "activitypub-miscellaneous-terms")] #[cfg(feature = "activitypub-miscellaneous-terms")]
fn moved_to(&self) -> Node<Self::Actor> { Node::Empty } fn moved_to(&self) -> Node<Self::Actor> { Node::Empty }
#[cfg(feature = "activitypub-miscellaneous-terms")] #[cfg(feature = "activitypub-miscellaneous-terms")]
fn manually_approves_followers(&self) -> Option<bool> { None } fn manually_approves_followers(&self) -> Option<bool> { None }
@ -35,6 +34,13 @@ pub trait Actor : Object {
#[cfg(feature = "activitypub-fe")] #[cfg(feature = "activitypub-fe")]
fn followed_by_me(&self) -> Option<bool> { None } fn followed_by_me(&self) -> Option<bool> { None }
#[cfg(feature = "activitypub-counters")]
fn followers_count(&self) -> Option<u64> { None }
#[cfg(feature = "activitypub-counters")]
fn following_count(&self) -> Option<u64> { None }
#[cfg(feature = "activitypub-counters")]
fn statuses_count(&self) -> Option<u64> { None }
// idk about this? everyone has it but AP doesn't mention it // idk about this? everyone has it but AP doesn't mention it
fn discoverable(&self) -> Option<bool> { None } fn discoverable(&self) -> Option<bool> { None }
} }
@ -63,6 +69,13 @@ pub trait ActorMut : ObjectMut {
#[cfg(feature = "activitypub-fe")] #[cfg(feature = "activitypub-fe")]
fn set_followed_by_me(self, val: Option<bool>) -> Self; fn set_followed_by_me(self, val: Option<bool>) -> Self;
#[cfg(feature = "activitypub-counters")]
fn set_followers_count(self, val: Option<u64>) -> Self;
#[cfg(feature = "activitypub-counters")]
fn set_following_count(self, val: Option<u64>) -> Self;
#[cfg(feature = "activitypub-counters")]
fn set_statuses_count(self, val: Option<u64>) -> Self;
fn set_discoverable(self, val: Option<bool>) -> Self; fn set_discoverable(self, val: Option<bool>) -> Self;
} }
@ -90,6 +103,13 @@ impl Actor for serde_json::Value {
#[cfg(feature = "activitypub-fe")] #[cfg(feature = "activitypub-fe")]
crate::getter! { followed_by_me::followedByMe -> bool } 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 } crate::getter! { discoverable -> bool }
fn endpoints(&self) -> Node<<Self as Object>::Object> { fn endpoints(&self) -> Node<<Self as Object>::Object> {
@ -121,6 +141,14 @@ impl ActorMut for serde_json::Value {
crate::setter! { following_me::followingMe -> bool } crate::setter! { following_me::followingMe -> bool }
#[cfg(feature = "activitypub-fe")] #[cfg(feature = "activitypub-fe")]
crate::setter! { followed_by_me::followedByMe -> bool } 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<<Self as Object>::Object>) -> Self { fn set_endpoints(mut self, _val: Node<<Self as Object>::Object>) -> Self {
self.as_object_mut().unwrap().insert("endpoints".to_string(), serde_json::Value::Object(serde_json::Map::default())); self.as_object_mut().unwrap().insert("endpoints".to_string(), serde_json::Value::Object(serde_json::Map::default()));
self self