From 827fb287dba66399fec2213ad65fe4eac1f0644f Mon Sep 17 00:00:00 2001 From: alemi Date: Fri, 7 Jun 2024 23:13:18 +0200 Subject: [PATCH] feat(apb): mentioning method for jut .to() and .bto() --- apb/src/target.rs | 37 +++++++++++++++++++++++++++------ upub/core/src/model/activity.rs | 6 ++++++ upub/core/src/model/object.rs | 6 ++++++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/apb/src/target.rs b/apb/src/target.rs index f130dd3c..9de517a5 100644 --- a/apb/src/target.rs +++ b/apb/src/target.rs @@ -4,7 +4,7 @@ pub const PUBLIC : &str = "https://www.w3.org/ns/activitystreams#Public"; pub trait Addressed { fn addressed(&self) -> Vec; // TODO rename this? remate others? idk - // fn primary_targets(&self) -> Vec; + fn mentioning(&self) -> Vec; // fn secondary_targets(&self) -> Vec; // fn public_targets(&self) -> Vec; // fn private_targets(&self) -> Vec; @@ -19,11 +19,11 @@ impl Addressed for T { to } - // fn primary_targets(&self) -> Vec { - // let mut to : Vec = self.to().ids(); - // to.append(&mut self.bto().ids()); - // to - // } + fn mentioning(&self) -> Vec { + let mut to : Vec = self.to().all_ids(); + to.append(&mut self.bto().all_ids()); + to + } // fn secondary_targets(&self) -> Vec { // let mut to : Vec = self.cc().ids(); @@ -73,4 +73,29 @@ mod test { ] ); } + + #[test] + #[cfg(feature = "unstructured")] + fn primary_targets_only_finds_to_and_bto() { + let obj = serde_json::json!({ + "id": "http://localhost:8080/obj/1", + "type": "Note", + "content": "hello world!", + "published": "2024-06-04T17:09:20+00:00", + "to": ["http://localhost:8080/usr/root/followers"], + "bto": ["https://localhost:8080/usr/secret"], + "cc": [crate::target::PUBLIC], + "bcc": [], + }); + + let addressed = obj.mentioning(); + + assert_eq!( + addressed, + vec![ + "http://localhost:8080/usr/root/followers".to_string(), + "https://localhost:8080/usr/secret".to_string(), + ] + ); + } } diff --git a/upub/core/src/model/activity.rs b/upub/core/src/model/activity.rs index 1697c673..45c14e1e 100644 --- a/upub/core/src/model/activity.rs +++ b/upub/core/src/model/activity.rs @@ -103,4 +103,10 @@ impl apb::target::Addressed for Model { to.append(&mut self.bcc.0.clone()); to } + + fn mentioning(&self) -> Vec { + let mut to = self.to.0.clone(); + to.append(&mut self.bto.0.clone()); + to + } } diff --git a/upub/core/src/model/object.rs b/upub/core/src/model/object.rs index 31655028..d44f4674 100644 --- a/upub/core/src/model/object.rs +++ b/upub/core/src/model/object.rs @@ -189,4 +189,10 @@ impl apb::target::Addressed for Model { to.append(&mut self.bcc.0.clone()); to } + + fn mentioning(&self) -> Vec { + let mut to = self.to.0.clone(); + to.append(&mut self.bto.0.clone()); + to + } }