fix: compact public target

fedify sets `to` as `as:Public` rather than the full IRI.......
This commit is contained in:
əlemi 2024-12-27 14:44:39 +01:00
parent d4c876a5d0
commit b350e4d9bb
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 10 additions and 5 deletions

View file

@ -1,6 +1,11 @@
use crate::Object; use crate::Object;
pub const PUBLIC : &str = "https://www.w3.org/ns/activitystreams#Public"; 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 { pub trait Addressed {
fn addressed(&self) -> Vec<String>; // TODO rename this? remate others? idk fn addressed(&self) -> Vec<String>; // TODO rename this? remate others? idk

View file

@ -18,7 +18,7 @@ impl Addresser for crate::Context {
for target in to.into_iter() for target in to.into_iter()
.filter(|to| !to.is_empty()) .filter(|to| !to.is_empty())
.filter(|to| crate::Context::server(to) != self.domain()) .filter(|to| crate::Context::server(to) != self.domain())
.filter(|to| to != apb::target::PUBLIC) .filter(|to| !apb::target::is_public(to))
{ {
// TODO fetch concurrently // TODO fetch concurrently
match self.fetch_user(&target, tx).await { match self.fetch_user(&target, tx).await {
@ -95,9 +95,9 @@ async fn address_to(ctx: &crate::Context, to: Vec<String>, aid: Option<i64>, oid
for target in to.into_iter() for target in to.into_iter()
.filter(|to| !to.is_empty()) .filter(|to| !to.is_empty())
.filter(|to| !to.ends_with("/followers")) .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 ( match (
crate::model::instance::Entity::domain_to_internal(&crate::Context::server(&target), tx).await?, crate::model::instance::Entity::domain_to_internal(&crate::Context::server(&target), tx).await?,
crate::model::actor::Entity::ap_to_internal(&target, tx).await?, crate::model::actor::Entity::ap_to_internal(&target, tx).await?,

View file

@ -66,10 +66,10 @@ impl Privacy {
} }
pub fn from_addressed(to: &[String], cc: &[String]) -> Self { 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; 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; return Self::Public;
} }
if to.iter().any(|x| x.ends_with("/followers")) if to.iter().any(|x| x.ends_with("/followers"))