mirror of
https://git.asonix.dog/asonix/relay.git
synced 2024-12-26 04:10:29 +00:00
Accept Undo Follow from already unfollowed actor
This commit is contained in:
parent
5a49c1f10c
commit
13ce219d76
3 changed files with 29 additions and 5 deletions
|
@ -24,6 +24,7 @@ pub enum UrlKind {
|
|||
Followers,
|
||||
Following,
|
||||
Inbox,
|
||||
Index,
|
||||
MainKey,
|
||||
NodeInfo,
|
||||
Outbox,
|
||||
|
@ -117,6 +118,7 @@ impl Config {
|
|||
UrlKind::Followers => format!("{}://{}/followers", scheme, self.hostname),
|
||||
UrlKind::Following => format!("{}://{}/following", scheme, self.hostname),
|
||||
UrlKind::Inbox => format!("{}://{}/inbox", scheme, self.hostname),
|
||||
UrlKind::Index => format!("{}://{}/", scheme, self.hostname),
|
||||
UrlKind::MainKey => format!("{}://{}/actor#main-key", scheme, self.hostname),
|
||||
UrlKind::NodeInfo => format!("{}://{}/nodeinfo/2.0.json", scheme, self.hostname),
|
||||
UrlKind::Outbox => format!("{}://{}/outbox", scheme, self.hostname),
|
||||
|
|
27
src/inbox.rs
27
src/inbox.rs
|
@ -50,7 +50,7 @@ pub async fn inbox(
|
|||
return Err(MyError::Whitelist(actor.id.to_string()));
|
||||
}
|
||||
|
||||
if input.kind != ValidTypes::Follow && !is_listener {
|
||||
if !is_listener && !valid_without_listener(&input) {
|
||||
return Err(MyError::NotSubscribed(actor.inbox().to_string()));
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,17 @@ pub async fn inbox(
|
|||
ValidTypes::Delete | ValidTypes::Update => {
|
||||
handle_forward(&state, &jobs, input, actor).await
|
||||
}
|
||||
ValidTypes::Undo => handle_undo(&db, &state, &config, &jobs, input, actor).await,
|
||||
ValidTypes::Undo => {
|
||||
handle_undo(&db, &state, &config, &jobs, input, actor, is_listener).await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn valid_without_listener(input: &AcceptedObjects) -> bool {
|
||||
match input.kind {
|
||||
ValidTypes::Follow => true,
|
||||
ValidTypes::Undo if input.object.is_kind("Follow") => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,6 +149,7 @@ async fn handle_undo(
|
|||
jobs: &JobServer,
|
||||
input: AcceptedObjects,
|
||||
actor: AcceptedActors,
|
||||
is_listener: bool,
|
||||
) -> Result<HttpResponse, MyError> {
|
||||
match input.object.kind() {
|
||||
Some("Follow") | Some("Announce") | Some("Create") => (),
|
||||
|
@ -150,7 +161,13 @@ async fn handle_undo(
|
|||
}
|
||||
|
||||
if !input.object.is_kind("Follow") {
|
||||
return handle_forward(state, jobs, input, actor).await;
|
||||
if is_listener {
|
||||
return handle_forward(state, jobs, input, actor).await;
|
||||
} else {
|
||||
return Err(MyError::Kind(
|
||||
input.object.kind().unwrap_or("unknown").to_owned(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
let my_id: XsdAnyUri = config.generate_url(UrlKind::Actor).parse()?;
|
||||
|
@ -159,6 +176,10 @@ async fn handle_undo(
|
|||
return Err(MyError::WrongActor(input.object.id().to_string()));
|
||||
}
|
||||
|
||||
if !is_listener {
|
||||
return Ok(accepted(serde_json::json!({})));
|
||||
}
|
||||
|
||||
let inbox = actor.inbox().to_owned();
|
||||
db.remove_listener(inbox).await?;
|
||||
|
||||
|
|
|
@ -37,9 +37,10 @@ impl State {
|
|||
self.private_key.clone(),
|
||||
self.actor_cache.clone(),
|
||||
format!(
|
||||
"{} {}",
|
||||
"Actix Web 3.0.0-alpha.1 ({}/{}; +{})",
|
||||
self.config.software_name(),
|
||||
self.config.software_version()
|
||||
self.config.software_version(),
|
||||
self.config.generate_url(UrlKind::Index),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue