From eb5e6b969b99b3281a0c8dbd9a22389b876c2a2d Mon Sep 17 00:00:00 2001 From: silverpill Date: Fri, 29 Jul 2022 09:27:05 +0000 Subject: [PATCH] Make subscribers part of primary audience of Note --- src/activitypub/builders/create_note.rs | 34 +++++++++++-------------- src/activitypub/builders/delete_note.rs | 2 +- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/activitypub/builders/create_note.rs b/src/activitypub/builders/create_note.rs index 554df09..0268e54 100644 --- a/src/activitypub/builders/create_note.rs +++ b/src/activitypub/builders/create_note.rs @@ -73,6 +73,7 @@ pub fn build_note( url: Some(url), } }).collect(); + let mut primary_audience = vec![]; let mut secondary_audience = vec![]; let followers_collection_id = @@ -92,11 +93,20 @@ pub fn build_note( }, Visibility::Direct => (), }; + let mut tags = vec![]; - for profile in &post.mentions { + let mut mentions = post.mentions.clone(); + if post.visibility == Visibility::Subscribers { + // Mention all subscribers + // (for recipients that don't support subscribers-only posts) + mentions.extend(subscribers); + }; + for profile in mentions { let tag_name = format!("@{}", profile.actor_address(instance_host)); let actor_id = profile.actor_id(instance_url); - primary_audience.push(actor_id.clone()); + if !primary_audience.contains(&actor_id) { + primary_audience.push(actor_id.clone()); + }; let tag = Tag { name: Some(tag_name), tag_type: MENTION.to_string(), @@ -104,21 +114,6 @@ pub fn build_note( }; tags.push(tag); }; - if matches!(post.visibility, Visibility::Subscribers) { - // Mention all subscribers - // (for recipients that don't support subscribers-only posts) - for profile in subscribers { - let tag_name = format!("@{}", profile.actor_address(instance_host)); - let actor_id = profile.actor_id(instance_url); - secondary_audience.push(actor_id.clone()); - let tag = Tag { - name: Some(tag_name), - tag_type: MENTION.to_string(), - href: Some(actor_id), - }; - tags.push(tag); - }; - }; for tag_name in &post.tags { let tag_page_url = get_tag_page_url(instance_url, tag_name); let tag = Tag { @@ -217,7 +212,7 @@ pub async fn prepare_create_note( post: &Post, ) -> Result, DatabaseError> { assert_eq!(author.id, post.author.id); - let subscribers = if matches!(post.visibility, Visibility::Subscribers) { + let subscribers = if post.visibility == Visibility::Subscribers { get_subscribers(db_client, &author.id).await? } else { vec![] @@ -305,8 +300,9 @@ mod tests { assert_eq!(note.to, vec![ local_actor_subscribers(INSTANCE_URL, &post.author.username), + subscriber_id.to_string(), ]); - assert_eq!(note.cc, vec![subscriber_id]); + assert_eq!(note.cc.is_empty(), true); } #[test] diff --git a/src/activitypub/builders/delete_note.rs b/src/activitypub/builders/delete_note.rs index 78578ef..3b6928a 100644 --- a/src/activitypub/builders/delete_note.rs +++ b/src/activitypub/builders/delete_note.rs @@ -57,7 +57,7 @@ pub async fn prepare_delete_note( post: &Post, ) -> Result, DatabaseError> { assert_eq!(author.id, post.author.id); - let subscribers = if matches!(post.visibility, Visibility::Subscribers) { + let subscribers = if post.visibility == Visibility::Subscribers { get_subscribers(db_client, &author.id).await? } else { vec![]