Set correct primary and secondary audience for outgoing Announce(Note) and Undo(Announce) activities
This commit is contained in:
parent
7a373831fe
commit
3e5f5b80d3
3 changed files with 36 additions and 40 deletions
|
@ -311,7 +311,7 @@ pub fn create_activity_announce(
|
||||||
Some(repost_id),
|
Some(repost_id),
|
||||||
object_id,
|
object_id,
|
||||||
vec![AP_PUBLIC.to_string(), recipient_id],
|
vec![AP_PUBLIC.to_string(), recipient_id],
|
||||||
vec![],
|
vec![get_followers_url(instance_url, &actor_profile.username)],
|
||||||
);
|
);
|
||||||
activity
|
activity
|
||||||
}
|
}
|
||||||
|
@ -320,24 +320,24 @@ pub fn create_activity_undo_announce(
|
||||||
instance_url: &str,
|
instance_url: &str,
|
||||||
actor_profile: &DbActorProfile,
|
actor_profile: &DbActorProfile,
|
||||||
repost_id: &Uuid,
|
repost_id: &Uuid,
|
||||||
recipient_id: Option<&String>,
|
recipient_id: &str,
|
||||||
) -> Activity {
|
) -> Activity {
|
||||||
let object_id = get_object_url(
|
let object_id = get_object_url(
|
||||||
instance_url,
|
instance_url,
|
||||||
repost_id,
|
repost_id,
|
||||||
);
|
);
|
||||||
let mut recipients = vec![AP_PUBLIC.to_string()];
|
let primary_audience = vec![
|
||||||
if let Some(recipient_id) = recipient_id {
|
AP_PUBLIC.to_string(),
|
||||||
recipients.push(recipient_id.to_string());
|
recipient_id.to_string(),
|
||||||
};
|
];
|
||||||
create_activity(
|
create_activity(
|
||||||
instance_url,
|
instance_url,
|
||||||
&actor_profile.username,
|
&actor_profile.username,
|
||||||
UNDO,
|
UNDO,
|
||||||
None,
|
None,
|
||||||
object_id,
|
object_id,
|
||||||
recipients,
|
primary_audience,
|
||||||
vec![],
|
vec![get_followers_url(instance_url, &actor_profile.username)],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,17 +30,17 @@ pub async fn get_note_audience(
|
||||||
|
|
||||||
pub struct Audience {
|
pub struct Audience {
|
||||||
pub recipients: Vec<Actor>,
|
pub recipients: Vec<Actor>,
|
||||||
pub primary_recipient: Option<String>,
|
pub primary_recipient: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_like_audience(
|
pub async fn get_like_audience(
|
||||||
_db_client: &impl GenericClient,
|
_db_client: &impl GenericClient,
|
||||||
|
instance_url: &str,
|
||||||
post: &Post,
|
post: &Post,
|
||||||
) -> Result<Audience, DatabaseError> {
|
) -> Result<Audience, DatabaseError> {
|
||||||
let mut recipients: Vec<Actor> = Vec::new();
|
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() {
|
if let Some(remote_actor) = post.author.actor_json.as_ref() {
|
||||||
primary_recipient = Some(remote_actor.id.clone());
|
|
||||||
recipients.push(remote_actor.clone());
|
recipients.push(remote_actor.clone());
|
||||||
};
|
};
|
||||||
Ok(Audience { recipients, primary_recipient })
|
Ok(Audience { recipients, primary_recipient })
|
||||||
|
@ -48,6 +48,7 @@ pub async fn get_like_audience(
|
||||||
|
|
||||||
pub async fn get_announce_audience(
|
pub async fn get_announce_audience(
|
||||||
db_client: &impl GenericClient,
|
db_client: &impl GenericClient,
|
||||||
|
instance_url: &str,
|
||||||
current_user: &User,
|
current_user: &User,
|
||||||
post: &Post,
|
post: &Post,
|
||||||
) -> Result<Audience, DatabaseError> {
|
) -> Result<Audience, DatabaseError> {
|
||||||
|
@ -58,9 +59,8 @@ pub async fn get_announce_audience(
|
||||||
recipients.push(remote_actor);
|
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() {
|
if let Some(remote_actor) = post.author.actor_json.as_ref() {
|
||||||
primary_recipient = Some(remote_actor.id.clone());
|
|
||||||
recipients.push(remote_actor.clone());
|
recipients.push(remote_actor.clone());
|
||||||
};
|
};
|
||||||
Ok(Audience { recipients, primary_recipient })
|
Ok(Audience { recipients, primary_recipient })
|
||||||
|
|
|
@ -215,20 +215,18 @@ async fn favourite(
|
||||||
get_actions_for_posts(db_client, ¤t_user.id, vec![&mut post]).await?;
|
get_actions_for_posts(db_client, ¤t_user.id, vec![&mut post]).await?;
|
||||||
|
|
||||||
if let Some(reaction) = maybe_reaction_created {
|
if let Some(reaction) = maybe_reaction_created {
|
||||||
|
// Federate
|
||||||
let Audience { recipients, primary_recipient } =
|
let Audience { recipients, primary_recipient } =
|
||||||
get_like_audience(db_client, &post).await?;
|
get_like_audience(db_client, &config.instance_url(), &post).await?;
|
||||||
if let Some(remote_actor_id) = primary_recipient {
|
let note_id = post.object_id.as_ref().ok_or(HttpError::InternalError)?;
|
||||||
// Federate
|
let activity = create_activity_like(
|
||||||
let object_id = post.object_id.as_ref().ok_or(HttpError::InternalError)?;
|
&config.instance_url(),
|
||||||
let activity = create_activity_like(
|
¤t_user.profile,
|
||||||
&config.instance_url(),
|
note_id,
|
||||||
¤t_user.profile,
|
&reaction.id,
|
||||||
object_id,
|
&primary_recipient,
|
||||||
&reaction.id,
|
);
|
||||||
&remote_actor_id,
|
deliver_activity(&config, ¤t_user, activity, recipients);
|
||||||
);
|
|
||||||
deliver_activity(&config, ¤t_user, activity, recipients);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let status = Status::from_post(post, &config.instance_url());
|
let status = Status::from_post(post, &config.instance_url());
|
||||||
|
@ -262,18 +260,16 @@ async fn unfavourite(
|
||||||
get_actions_for_posts(db_client, ¤t_user.id, vec![&mut post]).await?;
|
get_actions_for_posts(db_client, ¤t_user.id, vec![&mut post]).await?;
|
||||||
|
|
||||||
if let Some(reaction_id) = maybe_reaction_deleted {
|
if let Some(reaction_id) = maybe_reaction_deleted {
|
||||||
|
// Federate
|
||||||
let Audience { recipients, primary_recipient } =
|
let Audience { recipients, primary_recipient } =
|
||||||
get_like_audience(db_client, &post).await?;
|
get_like_audience(db_client, &config.instance_url(), &post).await?;
|
||||||
if let Some(remote_actor_id) = primary_recipient {
|
let activity = create_activity_undo_like(
|
||||||
// Federate
|
&config.instance_url(),
|
||||||
let activity = create_activity_undo_like(
|
¤t_user.profile,
|
||||||
&config.instance_url(),
|
&reaction_id,
|
||||||
¤t_user.profile,
|
&primary_recipient,
|
||||||
&reaction_id,
|
);
|
||||||
&remote_actor_id,
|
deliver_activity(&config, ¤t_user, activity, recipients);
|
||||||
);
|
|
||||||
deliver_activity(&config, ¤t_user, activity, recipients);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let status = Status::from_post(post, &config.instance_url());
|
let status = Status::from_post(post, &config.instance_url());
|
||||||
|
@ -300,7 +296,7 @@ async fn reblog(
|
||||||
|
|
||||||
// Federate
|
// Federate
|
||||||
let Audience { recipients, .. } =
|
let Audience { recipients, .. } =
|
||||||
get_announce_audience(db_client, ¤t_user, &post).await?;
|
get_announce_audience(db_client, &config.instance_url(), ¤t_user, &post).await?;
|
||||||
let activity = create_activity_announce(
|
let activity = create_activity_announce(
|
||||||
&config.instance_url(),
|
&config.instance_url(),
|
||||||
¤t_user.profile,
|
¤t_user.profile,
|
||||||
|
@ -332,12 +328,12 @@ async fn unreblog(
|
||||||
|
|
||||||
// Federate
|
// Federate
|
||||||
let Audience { recipients, primary_recipient } =
|
let Audience { recipients, primary_recipient } =
|
||||||
get_announce_audience(db_client, ¤t_user, &post).await?;
|
get_announce_audience(db_client, &config.instance_url(), ¤t_user, &post).await?;
|
||||||
let activity = create_activity_undo_announce(
|
let activity = create_activity_undo_announce(
|
||||||
&config.instance_url(),
|
&config.instance_url(),
|
||||||
¤t_user.profile,
|
¤t_user.profile,
|
||||||
repost_id,
|
repost_id,
|
||||||
primary_recipient.as_ref(),
|
&primary_recipient,
|
||||||
);
|
);
|
||||||
deliver_activity(&config, ¤t_user, activity, recipients);
|
deliver_activity(&config, ¤t_user, activity, recipients);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue