Accept Move() activities where object is local actor
This commit is contained in:
parent
df8c206cf0
commit
ff7c6724a0
1 changed files with 28 additions and 16 deletions
|
@ -7,6 +7,7 @@ use crate::activitypub::{
|
||||||
undo_follow::prepare_undo_follow,
|
undo_follow::prepare_undo_follow,
|
||||||
},
|
},
|
||||||
fetcher::helpers::get_or_import_profile_by_actor_id,
|
fetcher::helpers::get_or_import_profile_by_actor_id,
|
||||||
|
identifiers::parse_local_actor_id,
|
||||||
receiver::{find_object_id, parse_array},
|
receiver::{find_object_id, parse_array},
|
||||||
vocabulary::PERSON,
|
vocabulary::PERSON,
|
||||||
};
|
};
|
||||||
|
@ -20,7 +21,7 @@ use crate::models::{
|
||||||
get_followers,
|
get_followers,
|
||||||
unfollow,
|
unfollow,
|
||||||
},
|
},
|
||||||
users::queries::get_user_by_id,
|
users::queries::{get_user_by_id, get_user_by_name},
|
||||||
};
|
};
|
||||||
use super::HandlerResult;
|
use super::HandlerResult;
|
||||||
|
|
||||||
|
@ -42,13 +43,21 @@ pub async fn handle_move_person(
|
||||||
|
|
||||||
let instance = config.instance();
|
let instance = config.instance();
|
||||||
let media_dir = config.media_dir();
|
let media_dir = config.media_dir();
|
||||||
let old_profile = get_or_import_profile_by_actor_id(
|
let old_profile = if let Ok(username) = parse_local_actor_id(
|
||||||
|
&instance.url(),
|
||||||
|
&object_id,
|
||||||
|
) {
|
||||||
|
let old_user = get_user_by_name(db_client, &username).await?;
|
||||||
|
old_user.profile
|
||||||
|
} else {
|
||||||
|
get_or_import_profile_by_actor_id(
|
||||||
db_client,
|
db_client,
|
||||||
&instance,
|
&instance,
|
||||||
&media_dir,
|
&media_dir,
|
||||||
&object_id,
|
&object_id,
|
||||||
).await?;
|
).await?
|
||||||
let old_actor = old_profile.actor_json.unwrap();
|
};
|
||||||
|
let old_actor_id = old_profile.actor_id(&instance.url());
|
||||||
let new_profile = get_or_import_profile_by_actor_id(
|
let new_profile = get_or_import_profile_by_actor_id(
|
||||||
db_client,
|
db_client,
|
||||||
&instance,
|
&instance,
|
||||||
|
@ -78,7 +87,7 @@ pub async fn handle_move_person(
|
||||||
.map_err(|_| ValidationError("invalid alias list"))?;
|
.map_err(|_| ValidationError("invalid alias list"))?;
|
||||||
aliases.extend(also_known_as);
|
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());
|
return Err(ValidationError("target ID is not an alias").into());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -92,14 +101,17 @@ pub async fn handle_move_person(
|
||||||
&follower.id,
|
&follower.id,
|
||||||
&old_profile.id,
|
&old_profile.id,
|
||||||
).await?;
|
).await?;
|
||||||
// The target is remote profile, so follow request must exist
|
// Send Undo(Follow) if old actor is not local
|
||||||
let follow_request_id = maybe_follow_request_id.unwrap();
|
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(
|
activities.push(prepare_undo_follow(
|
||||||
&instance,
|
&instance,
|
||||||
&follower,
|
&follower,
|
||||||
&old_actor,
|
old_actor,
|
||||||
&follow_request_id,
|
&follow_request_id,
|
||||||
));
|
));
|
||||||
|
};
|
||||||
// Follow new profile
|
// Follow new profile
|
||||||
match create_follow_request(
|
match create_follow_request(
|
||||||
db_client,
|
db_client,
|
||||||
|
|
Loading…
Reference in a new issue