fix getting target from object for unfollow

https://github.com/astro/buzzrelay/issues/15
This commit is contained in:
Astro 2024-02-22 23:10:05 +01:00
parent d1a92f9f5e
commit b07c103fde
2 changed files with 16 additions and 15 deletions

View file

@ -84,26 +84,24 @@ impl Actor {
Some(Actor { host, kind })
}
pub fn from_object(action: &activitypub::Action<serde_json::Value>) -> Option<Self> {
let action_object = action.object.as_ref()?;
let mut action_target: Option<String> = 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<Self> {
let mut target: Option<String> = 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 {

View file

@ -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.