Support "as:Public" audience identifier

This commit is contained in:
silverpill 2023-01-12 23:58:14 +00:00
parent 5c2685c785
commit cbc78f9532
2 changed files with 7 additions and 6 deletions

View file

@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Added `/api/v1/settings/import_follows` API endpoint. - Added `/api/v1/settings/import_follows` API endpoint.
- Validation of Monero subscription payout address. - Validation of Monero subscription payout address.
- Accept webfinger requests where `resource` is actor ID. - Accept webfinger requests where `resource` is actor ID.
- Adeed support for `as:Public` audience identifier.
### Removed ### Removed

View file

@ -103,23 +103,23 @@ fn get_note_visibility(
primary_audience: Vec<String>, primary_audience: Vec<String>,
secondary_audience: Vec<String>, secondary_audience: Vec<String>,
) -> Visibility { ) -> Visibility {
if primary_audience.contains(&AP_PUBLIC.to_string()) || let audience = [primary_audience, secondary_audience].concat();
secondary_audience.contains(&AP_PUBLIC.to_string()) { // Some servers (e.g. Takahe) use "as" namespace
const PUBLIC_VARIANTS: [&str; 2] = [AP_PUBLIC, "as:Public"];
if audience.iter().any(|item| PUBLIC_VARIANTS.contains(&item.as_str())) {
return Visibility::Public; return Visibility::Public;
}; };
let maybe_followers = author.actor_json.as_ref() let maybe_followers = author.actor_json.as_ref()
.and_then(|actor| actor.followers.as_ref()); .and_then(|actor| actor.followers.as_ref());
if let Some(followers) = maybe_followers { if let Some(followers) = maybe_followers {
if primary_audience.contains(followers) || if audience.contains(followers) {
secondary_audience.contains(followers) {
return Visibility::Followers; return Visibility::Followers;
}; };
}; };
let maybe_subscribers = author.actor_json.as_ref() let maybe_subscribers = author.actor_json.as_ref()
.and_then(|actor| actor.subscribers.as_ref()); .and_then(|actor| actor.subscribers.as_ref());
if let Some(subscribers) = maybe_subscribers { if let Some(subscribers) = maybe_subscribers {
if primary_audience.contains(subscribers) || if audience.contains(subscribers) {
secondary_audience.contains(subscribers) {
return Visibility::Subscribers; return Visibility::Subscribers;
}; };
}; };