From b350e4d9bb5016b242cd9838f79136beca3c3cf5 Mon Sep 17 00:00:00 2001 From: alemi Date: Fri, 27 Dec 2024 14:44:39 +0100 Subject: [PATCH] fix: compact public target fedify sets `to` as `as:Public` rather than the full IRI....... --- apb/src/target.rs | 5 +++++ upub/core/src/traits/address.rs | 6 +++--- web/src/components/post.rs | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/apb/src/target.rs b/apb/src/target.rs index 9de517a..e0ffd9f 100644 --- a/apb/src/target.rs +++ b/apb/src/target.rs @@ -1,6 +1,11 @@ use crate::Object; pub const PUBLIC : &str = "https://www.w3.org/ns/activitystreams#Public"; +pub const PUBLIC_COMPACT: &str = "as:Public"; + +pub fn is_public(target: &str) -> bool { + target == PUBLIC || target == PUBLIC_COMPACT +} pub trait Addressed { fn addressed(&self) -> Vec; // TODO rename this? remate others? idk diff --git a/upub/core/src/traits/address.rs b/upub/core/src/traits/address.rs index e7aff75..de3f4b8 100644 --- a/upub/core/src/traits/address.rs +++ b/upub/core/src/traits/address.rs @@ -18,7 +18,7 @@ impl Addresser for crate::Context { for target in to.into_iter() .filter(|to| !to.is_empty()) .filter(|to| crate::Context::server(to) != self.domain()) - .filter(|to| to != apb::target::PUBLIC) + .filter(|to| !apb::target::is_public(to)) { // TODO fetch concurrently match self.fetch_user(&target, tx).await { @@ -95,9 +95,9 @@ async fn address_to(ctx: &crate::Context, to: Vec, aid: Option, oid for target in to.into_iter() .filter(|to| !to.is_empty()) .filter(|to| !to.ends_with("/followers")) - .filter(|to| local || to.as_str() == apb::target::PUBLIC || ctx.is_local(to)) + .filter(|to| local || apb::target::is_public(to.as_str()) || ctx.is_local(to)) { - let (server, actor) = if target == apb::target::PUBLIC { (None, None) } else { + let (server, actor) = if apb::target::is_public(&target) { (None, None) } else { match ( crate::model::instance::Entity::domain_to_internal(&crate::Context::server(&target), tx).await?, crate::model::actor::Entity::ap_to_internal(&target, tx).await?, diff --git a/web/src/components/post.rs b/web/src/components/post.rs index 38b8c27..b1eb2b9 100644 --- a/web/src/components/post.rs +++ b/web/src/components/post.rs @@ -66,10 +66,10 @@ impl Privacy { } pub fn from_addressed(to: &[String], cc: &[String]) -> Self { - if to.iter().any(|x| x == apb::target::PUBLIC) { + if to.iter().any(|x| apb::target::is_public(x)) { return Self::Broadcast; } - if cc.iter().any(|x| x == apb::target::PUBLIC) { + if cc.iter().any(|x| apb::target::is_public(x)) { return Self::Public; } if to.iter().any(|x| x.ends_with("/followers"))