2024-05-23 01:59:22 +02:00
|
|
|
use crate::Object;
|
2024-04-11 00:27:17 +02:00
|
|
|
|
|
|
|
pub const PUBLIC : &str = "https://www.w3.org/ns/activitystreams#Public";
|
|
|
|
|
2024-05-02 02:58:19 +02:00
|
|
|
pub trait Addressed {
|
2024-06-01 01:04:03 +02:00
|
|
|
fn addressed(&self) -> Vec<String>; // TODO rename this? remate others? idk
|
2024-06-07 23:13:18 +02:00
|
|
|
fn mentioning(&self) -> Vec<String>;
|
2024-06-01 01:26:19 +02:00
|
|
|
// fn secondary_targets(&self) -> Vec<String>;
|
|
|
|
// fn public_targets(&self) -> Vec<String>;
|
|
|
|
// fn private_targets(&self) -> Vec<String>;
|
2024-04-11 00:27:17 +02:00
|
|
|
}
|
|
|
|
|
2024-05-19 21:19:22 +02:00
|
|
|
impl<T: Object> Addressed for T {
|
2024-04-11 00:27:17 +02:00
|
|
|
fn addressed(&self) -> Vec<String> {
|
2024-06-01 01:26:19 +02:00
|
|
|
let mut to : Vec<String> = self.to().all_ids();
|
|
|
|
to.append(&mut self.bto().all_ids());
|
|
|
|
to.append(&mut self.cc().all_ids());
|
|
|
|
to.append(&mut self.bcc().all_ids());
|
2024-04-11 00:27:17 +02:00
|
|
|
to
|
|
|
|
}
|
2024-06-01 01:04:03 +02:00
|
|
|
|
2024-06-07 23:13:18 +02:00
|
|
|
fn mentioning(&self) -> Vec<String> {
|
|
|
|
let mut to : Vec<String> = self.to().all_ids();
|
|
|
|
to.append(&mut self.bto().all_ids());
|
|
|
|
to
|
|
|
|
}
|
2024-06-01 01:04:03 +02:00
|
|
|
|
2024-06-01 01:26:19 +02:00
|
|
|
// fn secondary_targets(&self) -> Vec<String> {
|
|
|
|
// let mut to : Vec<String> = self.cc().ids();
|
|
|
|
// to.append(&mut self.bcc().ids());
|
|
|
|
// to
|
|
|
|
// }
|
2024-06-01 01:04:03 +02:00
|
|
|
|
2024-06-01 01:26:19 +02:00
|
|
|
// fn public_targets(&self) -> Vec<String> {
|
|
|
|
// let mut to : Vec<String> = self.to().ids();
|
|
|
|
// to.append(&mut self.cc().ids());
|
|
|
|
// to
|
|
|
|
// }
|
2024-06-01 01:04:03 +02:00
|
|
|
|
2024-06-01 01:26:19 +02:00
|
|
|
// fn private_targets(&self) -> Vec<String> {
|
|
|
|
// let mut to : Vec<String> = self.bto().ids();
|
|
|
|
// to.append(&mut self.bcc().ids());
|
|
|
|
// to
|
|
|
|
// }
|
2024-04-11 00:27:17 +02:00
|
|
|
}
|
2024-06-06 16:22:47 +02:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::Addressed;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[cfg(feature = "unstructured")]
|
|
|
|
fn addressed_trait_finds_all_targets_on_json_objects() {
|
|
|
|
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.addressed();
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
addressed,
|
|
|
|
vec![
|
|
|
|
"http://localhost:8080/usr/root/followers".to_string(),
|
|
|
|
"https://localhost:8080/usr/secret".to_string(),
|
|
|
|
crate::target::PUBLIC.to_string(),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
2024-06-07 23:13:18 +02:00
|
|
|
|
|
|
|
#[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(),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
2024-06-06 16:22:47 +02:00
|
|
|
}
|