From d3c3180038fa82e90324fc2a1b5e68133ad090f4 Mon Sep 17 00:00:00 2001 From: Bat Date: Sat, 5 May 2018 14:46:06 +0100 Subject: [PATCH] Post activities to the correct inbox Don't assume everyone is following Plume's routing --- src/activity_pub/actor.rs | 8 +++++--- src/models/blogs.rs | 4 ++++ src/models/users.rs | 4 ++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/activity_pub/actor.rs b/src/activity_pub/actor.rs index 5d229f94..2699aceb 100644 --- a/src/activity_pub/actor.rs +++ b/src/activity_pub/actor.rs @@ -36,6 +36,8 @@ pub trait Actor: Sized { fn get_actor_type() -> ActorType; + fn get_inbox_url(&self) -> String; + fn custom_props(&self, _conn: &PgConnection) -> serde_json::Map { serde_json::Map::new() } @@ -88,15 +90,15 @@ pub trait Actor: Sized { let signed = act.sign(sender, conn); let res = Client::new() - .post(&self.compute_inbox(conn)[..]) + .post(&self.get_inbox_url()[..]) .headers(request::headers()) .header(request::signature(sender, request::headers(), conn)) .header(request::digest(signed.to_string())) .body(signed.to_string()) .send(); match res { - Ok(_) => println!("Successfully sent activity to inbox"), - Err(_) => println!("Error while sending to inbox") + Ok(mut r) => println!("Successfully sent activity to inbox ({})\n\n{:?}", self.get_inbox_url(), r.text().unwrap()), + Err(e) => println!("Error while sending to inbox ({:?})", e) } } diff --git a/src/models/blogs.rs b/src/models/blogs.rs index 8f0825e6..0ec72c4c 100644 --- a/src/models/blogs.rs +++ b/src/models/blogs.rs @@ -126,6 +126,10 @@ impl Actor for Blog { ActorType::Blog } + fn get_inbox_url(&self) -> String { + self.inbox_url.clone() + } + fn from_url(conn: &PgConnection, url: String) -> Option { blogs::table.filter(blogs::ap_url.eq(url)) .limit(1) diff --git a/src/models/users.rs b/src/models/users.rs index 4fc7e041..4712441f 100644 --- a/src/models/users.rs +++ b/src/models/users.rs @@ -263,6 +263,10 @@ impl Actor for User { ActorType::Person } + fn get_inbox_url(&self) -> String { + self.inbox_url.clone() + } + fn custom_props(&self, conn: &PgConnection) -> serde_json::Map { let mut res = serde_json::Map::new(); res.insert("publicKey".to_string(), json!({