diff --git a/apb/src/target.rs b/apb/src/target.rs index f130dd3..9de517a 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 1697c67..45c14e1 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 3165502..d44f467 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 + } }