Set correct primary and secondary audience for outgoing Announce(Note) and Undo(Announce) activities

This commit is contained in:
silverpill 2022-01-04 21:36:45 +00:00
parent 7a373831fe
commit 3e5f5b80d3
3 changed files with 36 additions and 40 deletions

View file

@ -311,7 +311,7 @@ pub fn create_activity_announce(
Some(repost_id),
object_id,
vec![AP_PUBLIC.to_string(), recipient_id],
vec![],
vec![get_followers_url(instance_url, &actor_profile.username)],
);
activity
}
@ -320,24 +320,24 @@ pub fn create_activity_undo_announce(
instance_url: &str,
actor_profile: &DbActorProfile,
repost_id: &Uuid,
recipient_id: Option<&String>,
recipient_id: &str,
) -> Activity {
let object_id = get_object_url(
instance_url,
repost_id,
);
let mut recipients = vec![AP_PUBLIC.to_string()];
if let Some(recipient_id) = recipient_id {
recipients.push(recipient_id.to_string());
};
let primary_audience = vec![
AP_PUBLIC.to_string(),
recipient_id.to_string(),
];
create_activity(
instance_url,
&actor_profile.username,
UNDO,
None,
object_id,
recipients,
vec![],
primary_audience,
vec![get_followers_url(instance_url, &actor_profile.username)],
)
}

View file

@ -30,17 +30,17 @@ pub async fn get_note_audience(
pub struct Audience {
pub recipients: Vec<Actor>,
pub primary_recipient: Option<String>,
pub primary_recipient: String,
}
pub async fn get_like_audience(
_db_client: &impl GenericClient,
instance_url: &str,
post: &Post,
) -> Result<Audience, DatabaseError> {
let mut recipients: Vec<Actor> = Vec::new();
let mut primary_recipient = None;
let primary_recipient = post.author.actor_id(instance_url);
if let Some(remote_actor) = post.author.actor_json.as_ref() {
primary_recipient = Some(remote_actor.id.clone());
recipients.push(remote_actor.clone());
};
Ok(Audience { recipients, primary_recipient })
@ -48,6 +48,7 @@ pub async fn get_like_audience(
pub async fn get_announce_audience(
db_client: &impl GenericClient,
instance_url: &str,
current_user: &User,
post: &Post,
) -> Result<Audience, DatabaseError> {
@ -58,9 +59,8 @@ pub async fn get_announce_audience(
recipients.push(remote_actor);
};
};
let mut primary_recipient = None;
let primary_recipient = post.author.actor_id(instance_url);
if let Some(remote_actor) = post.author.actor_json.as_ref() {
primary_recipient = Some(remote_actor.id.clone());
recipients.push(remote_actor.clone());
};
Ok(Audience { recipients, primary_recipient })

View file

@ -215,20 +215,18 @@ async fn favourite(
get_actions_for_posts(db_client, &current_user.id, vec![&mut post]).await?;
if let Some(reaction) = maybe_reaction_created {
// Federate
let Audience { recipients, primary_recipient } =
get_like_audience(db_client, &post).await?;
if let Some(remote_actor_id) = primary_recipient {
// Federate
let object_id = post.object_id.as_ref().ok_or(HttpError::InternalError)?;
let activity = create_activity_like(
&config.instance_url(),
&current_user.profile,
object_id,
&reaction.id,
&remote_actor_id,
);
deliver_activity(&config, &current_user, activity, recipients);
}
get_like_audience(db_client, &config.instance_url(), &post).await?;
let note_id = post.object_id.as_ref().ok_or(HttpError::InternalError)?;
let activity = create_activity_like(
&config.instance_url(),
&current_user.profile,
note_id,
&reaction.id,
&primary_recipient,
);
deliver_activity(&config, &current_user, activity, recipients);
}
let status = Status::from_post(post, &config.instance_url());
@ -262,18 +260,16 @@ async fn unfavourite(
get_actions_for_posts(db_client, &current_user.id, vec![&mut post]).await?;
if let Some(reaction_id) = maybe_reaction_deleted {
// Federate
let Audience { recipients, primary_recipient } =
get_like_audience(db_client, &post).await?;
if let Some(remote_actor_id) = primary_recipient {
// Federate
let activity = create_activity_undo_like(
&config.instance_url(),
&current_user.profile,
&reaction_id,
&remote_actor_id,
);
deliver_activity(&config, &current_user, activity, recipients);
};
get_like_audience(db_client, &config.instance_url(), &post).await?;
let activity = create_activity_undo_like(
&config.instance_url(),
&current_user.profile,
&reaction_id,
&primary_recipient,
);
deliver_activity(&config, &current_user, activity, recipients);
};
let status = Status::from_post(post, &config.instance_url());
@ -300,7 +296,7 @@ async fn reblog(
// Federate
let Audience { recipients, .. } =
get_announce_audience(db_client, &current_user, &post).await?;
get_announce_audience(db_client, &config.instance_url(), &current_user, &post).await?;
let activity = create_activity_announce(
&config.instance_url(),
&current_user.profile,
@ -332,12 +328,12 @@ async fn unreblog(
// Federate
let Audience { recipients, primary_recipient } =
get_announce_audience(db_client, &current_user, &post).await?;
get_announce_audience(db_client, &config.instance_url(), &current_user, &post).await?;
let activity = create_activity_undo_announce(
&config.instance_url(),
&current_user.profile,
repost_id,
primary_recipient.as_ref(),
&primary_recipient,
);
deliver_activity(&config, &current_user, activity, recipients);