diff --git a/src/config.rs b/src/config.rs index d334a0f..9b8b4ca 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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), diff --git a/src/inbox.rs b/src/inbox.rs index 5701de8..75648e4 100644 --- a/src/inbox.rs +++ b/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 { 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?; diff --git a/src/state.rs b/src/state.rs index 38ffdd5..55ec58d 100644 --- a/src/state.rs +++ b/src/state.rs @@ -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), ), ) }