mirror of
https://github.com/astro/buzzrelay.git
synced 2024-11-22 04:00:59 +00:00
implement unfollow
This commit is contained in:
parent
d3bf9a579e
commit
3b609f5b49
1 changed files with 27 additions and 2 deletions
29
src/main.rs
29
src/main.rs
|
@ -141,6 +141,9 @@ async fn post_relay(
|
||||||
format!("Bad action: {:?}", e)
|
format!("Bad action: {:?}", e)
|
||||||
).into_response(),
|
).into_response(),
|
||||||
};
|
};
|
||||||
|
let object_type = action.object
|
||||||
|
.and_then(|object| object.get("type").cloned())
|
||||||
|
.and_then(|object_type| object_type.as_str().map(|s| s.to_string()));
|
||||||
|
|
||||||
if action.action_type == "Follow" {
|
if action.action_type == "Follow" {
|
||||||
let priv_key = state.priv_key.clone();
|
let priv_key = state.priv_key.clone();
|
||||||
|
@ -162,11 +165,16 @@ async fn post_relay(
|
||||||
).await;
|
).await;
|
||||||
match result {
|
match result {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
state.database.add_follow(
|
match state.database.add_follow(
|
||||||
&endpoint.actor.id,
|
&endpoint.actor.id,
|
||||||
&endpoint.actor.inbox,
|
&endpoint.actor.inbox,
|
||||||
&target.uri(),
|
&target.uri(),
|
||||||
).await.unwrap();
|
).await {
|
||||||
|
Ok(()) => {}
|
||||||
|
Err(e) =>
|
||||||
|
// duplicate key constraint
|
||||||
|
tracing::error!("add_follow: {}", e),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!("post accept: {}", e);
|
tracing::error!("post accept: {}", e);
|
||||||
|
@ -178,6 +186,23 @@ async fn post_relay(
|
||||||
[("content-type", "application/activity+json")],
|
[("content-type", "application/activity+json")],
|
||||||
"{}"
|
"{}"
|
||||||
).into_response()
|
).into_response()
|
||||||
|
} else if action.action_type == "Undo" && object_type == Some("Follow".to_string()) {
|
||||||
|
match state.database.del_follow(
|
||||||
|
&endpoint.actor.id,
|
||||||
|
&target.uri(),
|
||||||
|
).await {
|
||||||
|
Ok(()) =>
|
||||||
|
(StatusCode::ACCEPTED,
|
||||||
|
[("content-type", "application/activity+json")],
|
||||||
|
"{}"
|
||||||
|
).into_response(),
|
||||||
|
Err(e) => {
|
||||||
|
tracing::error!("del_follow: {}", e);
|
||||||
|
(StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
format!("{}", e)
|
||||||
|
).into_response()
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO: Undo Follow
|
// TODO: Undo Follow
|
||||||
(StatusCode::BAD_REQUEST, "Not a recognized request").into_response()
|
(StatusCode::BAD_REQUEST, "Not a recognized request").into_response()
|
||||||
|
|
Loading…
Reference in a new issue