From ff7c6724a0fbcb0f7d7a7079f1608b2d95e89d2a Mon Sep 17 00:00:00 2001 From: silverpill Date: Sun, 27 Nov 2022 19:48:56 +0000 Subject: [PATCH] Accept Move() activities where object is local actor --- src/activitypub/handlers/move_person.rs | 44 ++++++++++++++++--------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/activitypub/handlers/move_person.rs b/src/activitypub/handlers/move_person.rs index 9c658c7..329df70 100644 --- a/src/activitypub/handlers/move_person.rs +++ b/src/activitypub/handlers/move_person.rs @@ -7,6 +7,7 @@ use crate::activitypub::{ undo_follow::prepare_undo_follow, }, fetcher::helpers::get_or_import_profile_by_actor_id, + identifiers::parse_local_actor_id, receiver::{find_object_id, parse_array}, vocabulary::PERSON, }; @@ -20,7 +21,7 @@ use crate::models::{ get_followers, unfollow, }, - users::queries::get_user_by_id, + users::queries::{get_user_by_id, get_user_by_name}, }; use super::HandlerResult; @@ -42,13 +43,21 @@ pub async fn handle_move_person( let instance = config.instance(); let media_dir = config.media_dir(); - let old_profile = get_or_import_profile_by_actor_id( - db_client, - &instance, - &media_dir, + let old_profile = if let Ok(username) = parse_local_actor_id( + &instance.url(), &object_id, - ).await?; - let old_actor = old_profile.actor_json.unwrap(); + ) { + let old_user = get_user_by_name(db_client, &username).await?; + old_user.profile + } else { + get_or_import_profile_by_actor_id( + db_client, + &instance, + &media_dir, + &object_id, + ).await? + }; + let old_actor_id = old_profile.actor_id(&instance.url()); let new_profile = get_or_import_profile_by_actor_id( db_client, &instance, @@ -78,7 +87,7 @@ pub async fn handle_move_person( .map_err(|_| ValidationError("invalid alias list"))?; aliases.extend(also_known_as); }; - if !aliases.iter().any(|actor_id| actor_id == &old_actor.id) { + if !aliases.iter().any(|actor_id| actor_id == &old_actor_id) { return Err(ValidationError("target ID is not an alias").into()); }; @@ -92,14 +101,17 @@ pub async fn handle_move_person( &follower.id, &old_profile.id, ).await?; - // The target is remote profile, so follow request must exist - let follow_request_id = maybe_follow_request_id.unwrap(); - activities.push(prepare_undo_follow( - &instance, - &follower, - &old_actor, - &follow_request_id, - )); + // Send Undo(Follow) if old actor is not local + if let Some(ref old_actor) = old_profile.actor_json { + let follow_request_id = maybe_follow_request_id + .expect("follow request must exist"); + activities.push(prepare_undo_follow( + &instance, + &follower, + old_actor, + &follow_request_id, + )); + }; // Follow new profile match create_follow_request( db_client,