diff --git a/src/actor.rs b/src/actor.rs index 1aab740..b2e5693 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -84,26 +84,24 @@ impl Actor { Some(Actor { host, kind }) } - pub fn from_object(action: &activitypub::Action) -> Option { - let action_object = action.object.as_ref()?; - - let mut action_target: Option = None; - if let Some(action_object) = action_object.as_str() { - action_target = Some(action_object.to_string()); + pub fn from_object(object: &serde_json::Value) -> Option { + let mut target: Option = None; + if let Some(object) = object.as_str() { + target = Some(object.to_string()); } - if let Some(action_object_0) = action_object.as_array() - .and_then(|action_object| { - if action_object.len() == 1 { - action_object.first() + if let Some(object_0) = object.as_array() + .and_then(|object| { + if object.len() == 1 { + object.first() } else { None } - }).and_then(|action_object_0| action_object_0.as_str()) + }).and_then(|object_0| object_0.as_str()) { - action_target = Some(action_object_0.to_string()); + target = Some(object_0.to_string()); } - action_target.and_then(|action_target| Self::from_uri(&action_target)) + target.and_then(|target| Self::from_uri(&target)) } pub fn uri(&self) -> String { diff --git a/src/main.rs b/src/main.rs index edddbe8..11867f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -188,7 +188,7 @@ async fn post_relay( let Ok(remote_actor) = remote_actor else { return (StatusCode::BAD_REQUEST, "Invalid actor").into_response(); }; - if let Some(action_target) = Actor::from_object(&action) { + if let Some(action_target) = action.object.and_then(|object| Actor::from_object(&object)) { if action_target.host == state.hostname { // A sharedInbox receives the actual follow target in the // `object` field. @@ -250,7 +250,10 @@ async fn post_relay( let Ok(remote_actor) = remote_actor else { return (StatusCode::BAD_REQUEST, "Invalid actor").into_response(); }; - if let Some(action_target) = Actor::from_object(&action) { + if let Some(action_target) = action.object + .and_then(|object| object.get("object") + .and_then(Actor::from_object)) + { if action_target.host == state.hostname { // A sharedInbox receives the actual follow target in the // `object` field.