From 389ad28d1491127f19eef5b843a6a9478b93323c Mon Sep 17 00:00:00 2001 From: Bat Date: Wed, 18 Jul 2018 15:49:13 +0200 Subject: [PATCH] Don't broadcast activities to local users Fix #80 --- plume-common/src/activity_pub/inbox.rs | 2 ++ plume-common/src/activity_pub/mod.rs | 1 + plume-models/src/blogs.rs | 4 ++++ plume-models/src/users.rs | 4 ++++ 4 files changed, 11 insertions(+) diff --git a/plume-common/src/activity_pub/inbox.rs b/plume-common/src/activity_pub/inbox.rs index 66855ff..6ce93c1 100644 --- a/plume-common/src/activity_pub/inbox.rs +++ b/plume-common/src/activity_pub/inbox.rs @@ -38,4 +38,6 @@ pub trait WithInbox { fn get_inbox_url(&self) -> String; fn get_shared_inbox_url(&self) -> Option; + + fn is_local(&self) -> bool; } diff --git a/plume-common/src/activity_pub/mod.rs b/plume-common/src/activity_pub/mod.rs index bd23d3a..841335f 100644 --- a/plume-common/src/activity_pub/mod.rs +++ b/plume-common/src/activity_pub/mod.rs @@ -84,6 +84,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for ApRequest { pub fn broadcast(sender: &S, act: A, to: Vec) { let boxes = to.into_iter() + .filter(|u| !u.is_local()) .map(|u| u.get_shared_inbox_url().unwrap_or(u.get_inbox_url())) .collect::>() .unique(); diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index 842eaff..736a1fc 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -257,6 +257,10 @@ impl WithInbox for Blog { fn get_shared_inbox_url(&self) -> Option { None } + + fn is_local(&self) -> bool { + self.instance_id == 0 + } } impl sign::Signer for Blog { diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index f3e41bd..333081e 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -421,6 +421,10 @@ impl WithInbox for User { fn get_shared_inbox_url(&self) -> Option { self.shared_inbox_url.clone() } + + fn is_local(&self) -> bool { + self.instance_id == 0 + } } impl Signer for User {