Pass instance as ref to activity builders
This commit is contained in:
parent
8f7dd5d88c
commit
65661698c7
16 changed files with 59 additions and 59 deletions
|
@ -40,21 +40,21 @@ fn build_accept_follow(
|
|||
}
|
||||
|
||||
pub fn prepare_accept_follow(
|
||||
instance: Instance,
|
||||
user: &User,
|
||||
instance: &Instance,
|
||||
sender: &User,
|
||||
source_actor: &Actor,
|
||||
follow_activity_id: &str,
|
||||
) -> OutgoingActivity<Activity> {
|
||||
let activity = build_accept_follow(
|
||||
&instance.url(),
|
||||
&user.profile,
|
||||
&sender.profile,
|
||||
&source_actor.id,
|
||||
follow_activity_id,
|
||||
);
|
||||
let recipients = vec![source_actor.clone()];
|
||||
OutgoingActivity {
|
||||
instance,
|
||||
sender: user.clone(),
|
||||
instance: instance.clone(),
|
||||
sender: sender.clone(),
|
||||
activity,
|
||||
recipients,
|
||||
}
|
||||
|
|
|
@ -77,25 +77,25 @@ pub async fn get_announce_note_recipients(
|
|||
|
||||
pub async fn prepare_announce_note(
|
||||
db_client: &impl GenericClient,
|
||||
instance: Instance,
|
||||
user: &User,
|
||||
instance: &Instance,
|
||||
sender: &User,
|
||||
repost: &Post,
|
||||
) -> Result<OutgoingActivity<Announce>, DatabaseError> {
|
||||
let post = repost.repost_of.as_ref().unwrap();
|
||||
let (recipients, _) = get_announce_note_recipients(
|
||||
db_client,
|
||||
&instance.url(),
|
||||
user,
|
||||
sender,
|
||||
post,
|
||||
).await?;
|
||||
let activity = build_announce_note(
|
||||
&instance.url(),
|
||||
&user.profile.username,
|
||||
&sender.profile.username,
|
||||
repost,
|
||||
);
|
||||
Ok(OutgoingActivity {
|
||||
instance,
|
||||
sender: user.clone(),
|
||||
instance: instance.clone(),
|
||||
sender: sender.clone(),
|
||||
activity,
|
||||
recipients,
|
||||
})
|
||||
|
|
|
@ -219,7 +219,7 @@ pub async fn get_note_recipients(
|
|||
|
||||
pub async fn prepare_create_note(
|
||||
db_client: &impl GenericClient,
|
||||
instance: Instance,
|
||||
instance: &Instance,
|
||||
author: &User,
|
||||
post: &Post,
|
||||
) -> Result<OutgoingActivity<Activity>, DatabaseError> {
|
||||
|
@ -231,7 +231,7 @@ pub async fn prepare_create_note(
|
|||
);
|
||||
let recipients = get_note_recipients(db_client, author, post).await?;
|
||||
Ok(OutgoingActivity {
|
||||
instance,
|
||||
instance: instance.clone(),
|
||||
sender: author.clone(),
|
||||
activity,
|
||||
recipients,
|
||||
|
|
|
@ -49,7 +49,7 @@ fn build_delete_note(
|
|||
|
||||
pub async fn prepare_delete_note(
|
||||
db_client: &impl GenericClient,
|
||||
instance: Instance,
|
||||
instance: &Instance,
|
||||
author: &User,
|
||||
post: &Post,
|
||||
) -> Result<OutgoingActivity<Activity>, DatabaseError> {
|
||||
|
@ -63,7 +63,7 @@ pub async fn prepare_delete_note(
|
|||
);
|
||||
let recipients = get_note_recipients(db_client, author, &post).await?;
|
||||
Ok(OutgoingActivity {
|
||||
instance,
|
||||
instance: instance.clone(),
|
||||
sender: author.clone(),
|
||||
activity,
|
||||
recipients,
|
||||
|
|
|
@ -47,13 +47,13 @@ async fn get_delete_person_recipients(
|
|||
|
||||
pub async fn prepare_delete_person(
|
||||
db_client: &impl GenericClient,
|
||||
instance: Instance,
|
||||
instance: &Instance,
|
||||
user: &User,
|
||||
) -> Result<OutgoingActivity<Activity>, DatabaseError> {
|
||||
let activity = build_delete_person(&instance.url(), user);
|
||||
let recipients = get_delete_person_recipients(db_client, &user.id).await?;
|
||||
Ok(OutgoingActivity {
|
||||
instance,
|
||||
instance: instance.clone(),
|
||||
sender: user.clone(),
|
||||
activity,
|
||||
recipients,
|
||||
|
|
|
@ -32,21 +32,21 @@ fn build_follow(
|
|||
}
|
||||
|
||||
pub fn prepare_follow(
|
||||
instance: Instance,
|
||||
user: &User,
|
||||
instance: &Instance,
|
||||
sender: &User,
|
||||
target_actor: &Actor,
|
||||
follow_request_id: &Uuid,
|
||||
) -> OutgoingActivity<Activity> {
|
||||
let activity = build_follow(
|
||||
&instance.url(),
|
||||
&user.profile,
|
||||
&sender.profile,
|
||||
&target_actor.id,
|
||||
follow_request_id,
|
||||
);
|
||||
let recipients = vec![target_actor.clone()];
|
||||
OutgoingActivity {
|
||||
instance,
|
||||
sender: user.clone(),
|
||||
instance: instance.clone(),
|
||||
sender: sender.clone(),
|
||||
activity,
|
||||
recipients,
|
||||
}
|
||||
|
|
|
@ -64,8 +64,8 @@ pub async fn get_like_note_recipients(
|
|||
|
||||
pub async fn prepare_like_note(
|
||||
db_client: &impl GenericClient,
|
||||
instance: Instance,
|
||||
user: &User,
|
||||
instance: &Instance,
|
||||
sender: &User,
|
||||
post: &Post,
|
||||
reaction_id: &Uuid,
|
||||
) -> Result<OutgoingActivity<Activity>, DatabaseError> {
|
||||
|
@ -78,15 +78,15 @@ pub async fn prepare_like_note(
|
|||
let note_author_id = post.author.actor_id(&instance.url());
|
||||
let activity = build_like_note(
|
||||
&instance.url(),
|
||||
&user.profile,
|
||||
&sender.profile,
|
||||
¬e_id,
|
||||
reaction_id,
|
||||
¬e_author_id,
|
||||
&post.visibility,
|
||||
);
|
||||
Ok(OutgoingActivity {
|
||||
instance,
|
||||
sender: user.clone(),
|
||||
instance: instance.clone(),
|
||||
sender: sender.clone(),
|
||||
activity,
|
||||
recipients,
|
||||
})
|
||||
|
|
|
@ -43,8 +43,8 @@ fn build_undo_announce(
|
|||
|
||||
pub async fn prepare_undo_announce_note(
|
||||
db_client: &impl GenericClient,
|
||||
instance: Instance,
|
||||
user: &User,
|
||||
instance: &Instance,
|
||||
sender: &User,
|
||||
post: &Post,
|
||||
repost_id: &Uuid,
|
||||
) -> Result<OutgoingActivity<Activity>, DatabaseError> {
|
||||
|
@ -52,18 +52,18 @@ pub async fn prepare_undo_announce_note(
|
|||
let (recipients, primary_recipient) = get_announce_note_recipients(
|
||||
db_client,
|
||||
&instance.url(),
|
||||
user,
|
||||
sender,
|
||||
post,
|
||||
).await?;
|
||||
let activity = build_undo_announce(
|
||||
&instance.url(),
|
||||
&user.profile,
|
||||
&sender.profile,
|
||||
repost_id,
|
||||
&primary_recipient,
|
||||
);
|
||||
Ok(OutgoingActivity {
|
||||
instance,
|
||||
sender: user.clone(),
|
||||
instance: instance.clone(),
|
||||
sender: sender.clone(),
|
||||
activity,
|
||||
recipients,
|
||||
})
|
||||
|
|
|
@ -49,21 +49,21 @@ fn build_undo_follow(
|
|||
}
|
||||
|
||||
pub fn prepare_undo_follow(
|
||||
instance: Instance,
|
||||
user: &User,
|
||||
instance: &Instance,
|
||||
sender: &User,
|
||||
target_actor: &Actor,
|
||||
follow_request_id: &Uuid,
|
||||
) -> OutgoingActivity<Activity> {
|
||||
let activity = build_undo_follow(
|
||||
&instance.url(),
|
||||
&user.profile,
|
||||
&sender.profile,
|
||||
&target_actor.id,
|
||||
follow_request_id,
|
||||
);
|
||||
let recipients = vec![target_actor.clone()];
|
||||
OutgoingActivity {
|
||||
instance,
|
||||
sender: user.clone(),
|
||||
instance: instance.clone(),
|
||||
sender: sender.clone(),
|
||||
activity,
|
||||
recipients,
|
||||
}
|
||||
|
|
|
@ -41,8 +41,8 @@ fn build_undo_like(
|
|||
|
||||
pub async fn prepare_undo_like_note(
|
||||
db_client: &impl GenericClient,
|
||||
instance: Instance,
|
||||
user: &User,
|
||||
instance: &Instance,
|
||||
sender: &User,
|
||||
post: &Post,
|
||||
reaction_id: &Uuid,
|
||||
) -> Result<OutgoingActivity<Activity>, DatabaseError> {
|
||||
|
@ -54,14 +54,14 @@ pub async fn prepare_undo_like_note(
|
|||
let note_author_id = post.author.actor_id(&instance.url());
|
||||
let activity = build_undo_like(
|
||||
&instance.url(),
|
||||
&user.profile,
|
||||
&sender.profile,
|
||||
reaction_id,
|
||||
¬e_author_id,
|
||||
&post.visibility,
|
||||
);
|
||||
Ok(OutgoingActivity {
|
||||
instance,
|
||||
sender: user.clone(),
|
||||
instance: instance.clone(),
|
||||
sender: sender.clone(),
|
||||
activity,
|
||||
recipients,
|
||||
})
|
||||
|
|
|
@ -53,14 +53,14 @@ async fn get_update_person_recipients(
|
|||
|
||||
pub async fn prepare_update_person(
|
||||
db_client: &impl GenericClient,
|
||||
instance: Instance,
|
||||
instance: &Instance,
|
||||
user: &User,
|
||||
) -> Result<OutgoingActivity<Activity>, DatabaseError> {
|
||||
let activity = build_update_person(&instance.url(), user)
|
||||
.map_err(|_| ConversionError)?;
|
||||
let recipients = get_update_person_recipients(db_client, &user.id).await?;
|
||||
Ok(OutgoingActivity {
|
||||
instance,
|
||||
instance: instance.clone(),
|
||||
sender: user.clone(),
|
||||
activity,
|
||||
recipients,
|
||||
|
|
|
@ -42,7 +42,7 @@ pub async fn handle_follow(
|
|||
|
||||
// Send activity
|
||||
prepare_accept_follow(
|
||||
config.instance(),
|
||||
&config.instance(),
|
||||
&target_user,
|
||||
&source_actor,
|
||||
&activity.id,
|
||||
|
|
|
@ -164,7 +164,7 @@ impl DeleteProfile {
|
|||
if profile.is_local() {
|
||||
let user = get_user_by_id(db_client, &profile.id).await?;
|
||||
let activity =
|
||||
prepare_delete_person(db_client, config.instance(), &user).await?;
|
||||
prepare_delete_person(db_client, &config.instance(), &user).await?;
|
||||
maybe_delete_person = Some(activity);
|
||||
};
|
||||
let deletion_queue = delete_profile(db_client, &profile.id).await?;
|
||||
|
@ -196,7 +196,7 @@ impl DeletePost {
|
|||
let author = get_user_by_id(db_client, &post.author.id).await?;
|
||||
let activity = prepare_delete_note(
|
||||
db_client,
|
||||
config.instance(),
|
||||
&config.instance(),
|
||||
&author,
|
||||
&post,
|
||||
).await?;
|
||||
|
|
|
@ -198,7 +198,7 @@ async fn update_credentials(
|
|||
).await?;
|
||||
|
||||
// Federate
|
||||
prepare_update_person(db_client, config.instance(), ¤t_user).await?
|
||||
prepare_update_person(db_client, &config.instance(), ¤t_user).await?
|
||||
.spawn_deliver();
|
||||
|
||||
let account = Account::from_user(current_user, &config.instance_url());
|
||||
|
@ -275,7 +275,7 @@ async fn create_identity_proof(
|
|||
).await?;
|
||||
|
||||
// Federate
|
||||
prepare_update_person(db_client, config.instance(), ¤t_user).await?
|
||||
prepare_update_person(db_client, &config.instance(), ¤t_user).await?
|
||||
.spawn_deliver();
|
||||
|
||||
let account = Account::from_user(current_user, &config.instance_url());
|
||||
|
@ -358,7 +358,7 @@ async fn follow_account(
|
|||
match create_follow_request(db_client, ¤t_user.id, &target.id).await {
|
||||
Ok(follow_request) => {
|
||||
prepare_follow(
|
||||
config.instance(),
|
||||
&config.instance(),
|
||||
¤t_user,
|
||||
&remote_actor,
|
||||
&follow_request.id,
|
||||
|
@ -408,7 +408,7 @@ async fn unfollow_account(
|
|||
let remote_actor = target.actor_json
|
||||
.ok_or(HttpError::InternalError)?;
|
||||
prepare_undo_follow(
|
||||
config.instance(),
|
||||
&config.instance(),
|
||||
¤t_user,
|
||||
&remote_actor,
|
||||
&follow_request_id,
|
||||
|
|
|
@ -194,7 +194,7 @@ async fn create_status(
|
|||
});
|
||||
post.linked = linked;
|
||||
// Federate
|
||||
prepare_create_note(db_client, instance.clone(), ¤t_user, &post).await?
|
||||
prepare_create_note(db_client, &instance, ¤t_user, &post).await?
|
||||
.spawn_deliver();
|
||||
|
||||
let status = Status::from_post(post, &instance.url());
|
||||
|
@ -241,7 +241,7 @@ async fn delete_status(
|
|||
};
|
||||
let delete_note = prepare_delete_note(
|
||||
db_client,
|
||||
config.instance(),
|
||||
&config.instance(),
|
||||
¤t_user,
|
||||
&post,
|
||||
).await?;
|
||||
|
@ -308,7 +308,7 @@ async fn favourite(
|
|||
// Federate
|
||||
prepare_like_note(
|
||||
db_client,
|
||||
config.instance(),
|
||||
&config.instance(),
|
||||
¤t_user,
|
||||
&post,
|
||||
&reaction.id,
|
||||
|
@ -349,7 +349,7 @@ async fn unfavourite(
|
|||
// Federate
|
||||
prepare_undo_like_note(
|
||||
db_client,
|
||||
config.instance(),
|
||||
&config.instance(),
|
||||
¤t_user,
|
||||
&post,
|
||||
&reaction_id,
|
||||
|
@ -386,7 +386,7 @@ async fn reblog(
|
|||
// Federate
|
||||
prepare_announce_note(
|
||||
db_client,
|
||||
config.instance(),
|
||||
&config.instance(),
|
||||
¤t_user,
|
||||
&repost,
|
||||
).await?.spawn_deliver();
|
||||
|
@ -422,7 +422,7 @@ async fn unreblog(
|
|||
// Federate
|
||||
prepare_undo_announce_note(
|
||||
db_client,
|
||||
config.instance(),
|
||||
&config.instance(),
|
||||
¤t_user,
|
||||
&post,
|
||||
repost_id,
|
||||
|
|
|
@ -142,7 +142,7 @@ pub async fn register_subscription_option(
|
|||
).await?;
|
||||
|
||||
// Federate
|
||||
prepare_update_person(db_client, config.instance(), ¤t_user)
|
||||
prepare_update_person(db_client, &config.instance(), ¤t_user)
|
||||
.await?.spawn_deliver();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue