Fix audience of private Delete(Note) activity

This commit is contained in:
silverpill 2022-07-28 23:50:01 +00:00
parent aefed2479e
commit a70c841955
2 changed files with 32 additions and 8 deletions

View file

@ -51,8 +51,8 @@ pub struct Note {
#[serde(skip_serializing_if = "Vec::is_empty")] #[serde(skip_serializing_if = "Vec::is_empty")]
tag: Vec<Tag>, tag: Vec<Tag>,
to: Vec<String>, pub to: Vec<String>,
cc: Vec<String>, pub cc: Vec<String>,
} }
pub fn build_note( pub fn build_note(

View file

@ -2,18 +2,26 @@ use serde_json::json;
use tokio_postgres::GenericClient; use tokio_postgres::GenericClient;
use crate::activitypub::activity::{create_activity, Activity, Object}; use crate::activitypub::activity::{create_activity, Activity, Object};
use crate::activitypub::constants::{AP_CONTEXT, AP_PUBLIC}; use crate::activitypub::constants::AP_CONTEXT;
use crate::activitypub::deliverer::OutgoingActivity; use crate::activitypub::deliverer::OutgoingActivity;
use crate::activitypub::vocabulary::{DELETE, NOTE, TOMBSTONE}; use crate::activitypub::vocabulary::{DELETE, NOTE, TOMBSTONE};
use crate::config::Instance; use crate::config::Instance;
use crate::errors::DatabaseError; use crate::errors::DatabaseError;
use crate::models::posts::types::Post; use crate::models::posts::types::{Post, Visibility};
use crate::models::profiles::types::DbActorProfile;
use crate::models::relationships::queries::get_subscribers;
use crate::models::users::types::User; use crate::models::users::types::User;
use super::create_note::get_note_recipients; use super::create_note::{
build_note,
get_note_recipients,
Note,
};
fn build_delete_note( fn build_delete_note(
instance_host: &str,
instance_url: &str, instance_url: &str,
post: &Post, post: &Post,
subscribers: Vec<DbActorProfile>,
) -> Activity { ) -> Activity {
let object_id = post.get_object_id(instance_url); let object_id = post.get_object_id(instance_url);
let object = Object { let object = Object {
@ -24,14 +32,20 @@ fn build_delete_note(
..Default::default() ..Default::default()
}; };
let activity_id = format!("{}/delete", object.id); let activity_id = format!("{}/delete", object.id);
let Note { to, cc, .. } = build_note(
instance_host,
instance_url,
post,
subscribers,
);
let activity = create_activity( let activity = create_activity(
instance_url, instance_url,
&post.author.username, &post.author.username,
DELETE, DELETE,
activity_id, activity_id,
object, object,
vec![AP_PUBLIC.to_string()], to,
vec![], cc,
); );
activity activity
} }
@ -43,7 +57,17 @@ pub async fn prepare_delete_note(
post: &Post, post: &Post,
) -> Result<OutgoingActivity<Activity>, DatabaseError> { ) -> Result<OutgoingActivity<Activity>, DatabaseError> {
assert_eq!(author.id, post.author.id); assert_eq!(author.id, post.author.id);
let activity = build_delete_note(&instance.url(), post); let subscribers = if matches!(post.visibility, Visibility::Subscribers) {
get_subscribers(db_client, &author.id).await?
} else {
vec![]
};
let activity = build_delete_note(
&instance.host(),
&instance.url(),
post,
subscribers,
);
let recipients = get_note_recipients(db_client, author, post).await?; let recipients = get_note_recipients(db_client, author, post).await?;
Ok(OutgoingActivity { Ok(OutgoingActivity {
instance, instance,