mirror of
https://github.com/astro/buzzrelay.git
synced 2024-11-25 05:20:59 +00:00
fix getting target from object for unfollow
https://github.com/astro/buzzrelay/issues/15
This commit is contained in:
parent
d1a92f9f5e
commit
b07c103fde
2 changed files with 16 additions and 15 deletions
24
src/actor.rs
24
src/actor.rs
|
@ -84,26 +84,24 @@ impl Actor {
|
||||||
Some(Actor { host, kind })
|
Some(Actor { host, kind })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_object(action: &activitypub::Action<serde_json::Value>) -> Option<Self> {
|
pub fn from_object(object: &serde_json::Value) -> Option<Self> {
|
||||||
let action_object = action.object.as_ref()?;
|
let mut target: Option<String> = None;
|
||||||
|
if let Some(object) = object.as_str() {
|
||||||
let mut action_target: Option<String> = None;
|
target = Some(object.to_string());
|
||||||
if let Some(action_object) = action_object.as_str() {
|
|
||||||
action_target = Some(action_object.to_string());
|
|
||||||
}
|
}
|
||||||
if let Some(action_object_0) = action_object.as_array()
|
if let Some(object_0) = object.as_array()
|
||||||
.and_then(|action_object| {
|
.and_then(|object| {
|
||||||
if action_object.len() == 1 {
|
if object.len() == 1 {
|
||||||
action_object.first()
|
object.first()
|
||||||
} else {
|
} else {
|
||||||
None
|
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 {
|
pub fn uri(&self) -> String {
|
||||||
|
|
|
@ -188,7 +188,7 @@ async fn post_relay(
|
||||||
let Ok(remote_actor) = remote_actor else {
|
let Ok(remote_actor) = remote_actor else {
|
||||||
return (StatusCode::BAD_REQUEST, "Invalid actor").into_response();
|
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 {
|
if action_target.host == state.hostname {
|
||||||
// A sharedInbox receives the actual follow target in the
|
// A sharedInbox receives the actual follow target in the
|
||||||
// `object` field.
|
// `object` field.
|
||||||
|
@ -250,7 +250,10 @@ async fn post_relay(
|
||||||
let Ok(remote_actor) = remote_actor else {
|
let Ok(remote_actor) = remote_actor else {
|
||||||
return (StatusCode::BAD_REQUEST, "Invalid actor").into_response();
|
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 {
|
if action_target.host == state.hostname {
|
||||||
// A sharedInbox receives the actual follow target in the
|
// A sharedInbox receives the actual follow target in the
|
||||||
// `object` field.
|
// `object` field.
|
||||||
|
|
Loading…
Reference in a new issue