From 98fa0dc58fea602f4d3c5207478765c787b73e55 Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 9 Nov 2024 11:58:06 +0100 Subject: [PATCH] fix: sub-address only if necessary --- upub/core/src/traits/address.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/upub/core/src/traits/address.rs b/upub/core/src/traits/address.rs index a2e61dc..5d827b3 100644 --- a/upub/core/src/traits/address.rs +++ b/upub/core/src/traits/address.rs @@ -69,12 +69,19 @@ impl Addresser for crate::Context { (Some(activity), Some(object)) => { let to_activity = BTreeSet::from_iter(expand_addressing(activity.addressed(), None, tx).await?); let to_object = BTreeSet::from_iter(expand_addressing(object.addressed(), object.audience.clone(), tx).await?); + let to_common = to_activity.intersection(&to_object).cloned().collect(); address_to(self, to_common, Some(activity.internal), Some(object.internal), self.is_local(&activity.id), activity.published, tx).await?; - let to_only_activity = (&to_activity - &to_object).into_iter().collect(); - address_to(self, to_only_activity, Some(activity.internal), None, self.is_local(&activity.id), activity.published, tx).await?; - let to_only_object = (&to_object - &to_activity).into_iter().collect(); - address_to(self, to_only_object, None, Some(object.internal), self.is_local(&activity.id), object.published, tx).await?; + + let to_only_activity: Vec = (&to_activity - &to_object).into_iter().collect(); + if !to_only_activity.is_empty() { + address_to(self, to_only_activity, Some(activity.internal), None, self.is_local(&activity.id), activity.published, tx).await?; + } + + let to_only_object: Vec = (&to_object - &to_activity).into_iter().collect(); + if !to_only_object.is_empty() { + address_to(self, to_only_object, None, Some(object.internal), self.is_local(&activity.id), object.published, tx).await?; + } Ok(()) }, }