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,
|
||||
},
|
||||
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,
|
||||
|
|
Loading…
Reference in a new issue