Post activities to the correct inbox

Don't assume everyone is following Plume's routing
This commit is contained in:
Bat 2018-05-05 14:46:06 +01:00
parent b36e83049c
commit d3c3180038
3 changed files with 13 additions and 3 deletions

View file

@ -36,6 +36,8 @@ pub trait Actor: Sized {
fn get_actor_type() -> ActorType; fn get_actor_type() -> ActorType;
fn get_inbox_url(&self) -> String;
fn custom_props(&self, _conn: &PgConnection) -> serde_json::Map<String, serde_json::Value> { fn custom_props(&self, _conn: &PgConnection) -> serde_json::Map<String, serde_json::Value> {
serde_json::Map::new() serde_json::Map::new()
} }
@ -88,15 +90,15 @@ pub trait Actor: Sized {
let signed = act.sign(sender, conn); let signed = act.sign(sender, conn);
let res = Client::new() let res = Client::new()
.post(&self.compute_inbox(conn)[..]) .post(&self.get_inbox_url()[..])
.headers(request::headers()) .headers(request::headers())
.header(request::signature(sender, request::headers(), conn)) .header(request::signature(sender, request::headers(), conn))
.header(request::digest(signed.to_string())) .header(request::digest(signed.to_string()))
.body(signed.to_string()) .body(signed.to_string())
.send(); .send();
match res { match res {
Ok(_) => println!("Successfully sent activity to inbox"), Ok(mut r) => println!("Successfully sent activity to inbox ({})\n\n{:?}", self.get_inbox_url(), r.text().unwrap()),
Err(_) => println!("Error while sending to inbox") Err(e) => println!("Error while sending to inbox ({:?})", e)
} }
} }

View file

@ -126,6 +126,10 @@ impl Actor for Blog {
ActorType::Blog ActorType::Blog
} }
fn get_inbox_url(&self) -> String {
self.inbox_url.clone()
}
fn from_url(conn: &PgConnection, url: String) -> Option<Blog> { fn from_url(conn: &PgConnection, url: String) -> Option<Blog> {
blogs::table.filter(blogs::ap_url.eq(url)) blogs::table.filter(blogs::ap_url.eq(url))
.limit(1) .limit(1)

View file

@ -263,6 +263,10 @@ impl Actor for User {
ActorType::Person ActorType::Person
} }
fn get_inbox_url(&self) -> String {
self.inbox_url.clone()
}
fn custom_props(&self, conn: &PgConnection) -> serde_json::Map<String, serde_json::Value> { fn custom_props(&self, conn: &PgConnection) -> serde_json::Map<String, serde_json::Value> {
let mut res = serde_json::Map::new(); let mut res = serde_json::Map::new();
res.insert("publicKey".to_string(), json!({ res.insert("publicKey".to_string(), json!({