From 65661698c7269e5372c096045739155c7f00780c Mon Sep 17 00:00:00 2001 From: silverpill Date: Sat, 22 Oct 2022 00:15:28 +0000 Subject: [PATCH] Pass instance as ref to activity builders --- src/activitypub/builders/accept_follow.rs | 10 +++++----- src/activitypub/builders/announce_note.rs | 12 ++++++------ src/activitypub/builders/create_note.rs | 4 ++-- src/activitypub/builders/delete_note.rs | 4 ++-- src/activitypub/builders/delete_person.rs | 4 ++-- src/activitypub/builders/follow.rs | 10 +++++----- src/activitypub/builders/like_note.rs | 10 +++++----- src/activitypub/builders/undo_announce_note.rs | 12 ++++++------ src/activitypub/builders/undo_follow.rs | 10 +++++----- src/activitypub/builders/undo_like_note.rs | 10 +++++----- src/activitypub/builders/update_person.rs | 4 ++-- src/activitypub/handlers/follow.rs | 2 +- src/cli.rs | 4 ++-- src/mastodon_api/accounts/views.rs | 8 ++++---- src/mastodon_api/statuses/views.rs | 12 ++++++------ src/mastodon_api/subscriptions/views.rs | 2 +- 16 files changed, 59 insertions(+), 59 deletions(-) diff --git a/src/activitypub/builders/accept_follow.rs b/src/activitypub/builders/accept_follow.rs index 1c03078..9e665bd 100644 --- a/src/activitypub/builders/accept_follow.rs +++ b/src/activitypub/builders/accept_follow.rs @@ -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 { 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, } diff --git a/src/activitypub/builders/announce_note.rs b/src/activitypub/builders/announce_note.rs index d46a6ae..3813293 100644 --- a/src/activitypub/builders/announce_note.rs +++ b/src/activitypub/builders/announce_note.rs @@ -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, 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, }) diff --git a/src/activitypub/builders/create_note.rs b/src/activitypub/builders/create_note.rs index 5a387bd..021b9a5 100644 --- a/src/activitypub/builders/create_note.rs +++ b/src/activitypub/builders/create_note.rs @@ -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, 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, diff --git a/src/activitypub/builders/delete_note.rs b/src/activitypub/builders/delete_note.rs index 7a03644..1511efc 100644 --- a/src/activitypub/builders/delete_note.rs +++ b/src/activitypub/builders/delete_note.rs @@ -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, 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, diff --git a/src/activitypub/builders/delete_person.rs b/src/activitypub/builders/delete_person.rs index 279e731..5e67b2f 100644 --- a/src/activitypub/builders/delete_person.rs +++ b/src/activitypub/builders/delete_person.rs @@ -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, 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, diff --git a/src/activitypub/builders/follow.rs b/src/activitypub/builders/follow.rs index a46f9ee..3d8f97e 100644 --- a/src/activitypub/builders/follow.rs +++ b/src/activitypub/builders/follow.rs @@ -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 { 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, } diff --git a/src/activitypub/builders/like_note.rs b/src/activitypub/builders/like_note.rs index a1b4fe0..157740c 100644 --- a/src/activitypub/builders/like_note.rs +++ b/src/activitypub/builders/like_note.rs @@ -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, 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, }) diff --git a/src/activitypub/builders/undo_announce_note.rs b/src/activitypub/builders/undo_announce_note.rs index c9920cb..a13fd42 100644 --- a/src/activitypub/builders/undo_announce_note.rs +++ b/src/activitypub/builders/undo_announce_note.rs @@ -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, 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, }) diff --git a/src/activitypub/builders/undo_follow.rs b/src/activitypub/builders/undo_follow.rs index cce7a14..2964e78 100644 --- a/src/activitypub/builders/undo_follow.rs +++ b/src/activitypub/builders/undo_follow.rs @@ -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 { 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, } diff --git a/src/activitypub/builders/undo_like_note.rs b/src/activitypub/builders/undo_like_note.rs index b01c821..26276b3 100644 --- a/src/activitypub/builders/undo_like_note.rs +++ b/src/activitypub/builders/undo_like_note.rs @@ -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, 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, }) diff --git a/src/activitypub/builders/update_person.rs b/src/activitypub/builders/update_person.rs index eb2aa4a..3eb713f 100644 --- a/src/activitypub/builders/update_person.rs +++ b/src/activitypub/builders/update_person.rs @@ -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, 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, diff --git a/src/activitypub/handlers/follow.rs b/src/activitypub/handlers/follow.rs index 2d87093..a1c4c91 100644 --- a/src/activitypub/handlers/follow.rs +++ b/src/activitypub/handlers/follow.rs @@ -42,7 +42,7 @@ pub async fn handle_follow( // Send activity prepare_accept_follow( - config.instance(), + &config.instance(), &target_user, &source_actor, &activity.id, diff --git a/src/cli.rs b/src/cli.rs index 6e1b7a4..c459a43 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -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?; diff --git a/src/mastodon_api/accounts/views.rs b/src/mastodon_api/accounts/views.rs index a74d070..acfb5fe 100644 --- a/src/mastodon_api/accounts/views.rs +++ b/src/mastodon_api/accounts/views.rs @@ -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, diff --git a/src/mastodon_api/statuses/views.rs b/src/mastodon_api/statuses/views.rs index 4e519e0..23d0f7d 100644 --- a/src/mastodon_api/statuses/views.rs +++ b/src/mastodon_api/statuses/views.rs @@ -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, diff --git a/src/mastodon_api/subscriptions/views.rs b/src/mastodon_api/subscriptions/views.rs index 3831f82..5ff7533 100644 --- a/src/mastodon_api/subscriptions/views.rs +++ b/src/mastodon_api/subscriptions/views.rs @@ -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(); };