Avoid calling compute_id when we shouldn't

It should only be used at initialization, after we should prefer ap_url,
as not everybody is using the same URLs as Plume.
This commit is contained in:
Bat 2018-06-21 15:48:54 +01:00
parent 514689cfc1
commit 5457a80eec
7 changed files with 20 additions and 20 deletions

View file

@ -175,12 +175,12 @@ impl Blog {
pub fn webfinger(&self, conn: &PgConnection) -> Webfinger { pub fn webfinger(&self, conn: &PgConnection) -> Webfinger {
Webfinger { Webfinger {
subject: format!("acct:{}@{}", self.actor_id, self.get_instance(conn).public_domain), subject: format!("acct:{}@{}", self.actor_id, self.get_instance(conn).public_domain),
aliases: vec![self.compute_id(conn)], aliases: vec![self.ap_url.clone()],
links: vec![ links: vec![
Link { Link {
rel: String::from("http://webfinger.net/rel/profile-page"), rel: String::from("http://webfinger.net/rel/profile-page"),
mime_type: None, mime_type: None,
href: self.compute_id(conn) href: self.ap_url.clone()
}, },
Link { Link {
rel: String::from("http://schemas.google.com/g/2010#updates-from"), rel: String::from("http://schemas.google.com/g/2010#updates-from"),
@ -190,7 +190,7 @@ impl Blog {
Link { Link {
rel: String::from("self"), rel: String::from("self"),
mime_type: Some(String::from("application/activity+json")), mime_type: Some(String::from("application/activity+json")),
href: self.compute_id(conn) href: self.ap_url.clone()
} }
] ]
} }
@ -259,8 +259,8 @@ impl APActor for Blog {
} }
impl sign::Signer for Blog { impl sign::Signer for Blog {
fn get_key_id(&self, conn: &PgConnection) -> String { fn get_key_id(&self, _conn: &PgConnection) -> String {
format!("{}#main-key", self.compute_id(conn)) format!("{}#main-key", self.ap_url)
} }
fn sign(&self, to_sign: String) -> Vec<u8> { fn sign(&self, to_sign: String) -> Vec<u8> {

View file

@ -84,7 +84,7 @@ impl Comment {
} }
pub fn compute_id(&self, conn: &PgConnection) -> String { pub fn compute_id(&self, conn: &PgConnection) -> String {
ap_url(format!("{}#comment-{}", self.get_post(conn).compute_id(conn), self.id)) ap_url(format!("{}#comment-{}", self.get_post(conn).ap_url, self.id))
} }
} }

View file

@ -70,8 +70,8 @@ impl Like {
pub fn compute_id(&self, conn: &PgConnection) -> String { pub fn compute_id(&self, conn: &PgConnection) -> String {
format!( format!(
"{}/like/{}", "{}/like/{}",
User::get(conn, self.user_id).unwrap().compute_id(conn), User::get(conn, self.user_id).unwrap().ap_url,
Post::get(conn, self.post_id).unwrap().compute_id(conn) Post::get(conn, self.post_id).unwrap().ap_url
) )
} }
} }

View file

@ -155,7 +155,7 @@ impl Post {
content: Some(serde_json::to_value(self.content.clone()).unwrap()), content: Some(serde_json::to_value(self.content.clone()).unwrap()),
published: Some(serde_json::to_value(self.creation_date).unwrap()), published: Some(serde_json::to_value(self.creation_date).unwrap()),
tag: Some(serde_json::to_value(mentions).unwrap()), tag: Some(serde_json::to_value(mentions).unwrap()),
url: Some(serde_json::to_value(self.compute_id(conn)).unwrap()), url: Some(serde_json::to_value(self.ap_url.clone()).unwrap()),
to: Some(serde_json::to_value(to).unwrap()), to: Some(serde_json::to_value(to).unwrap()),
cc: Some(serde_json::to_value(Vec::<serde_json::Value>::new()).unwrap()), cc: Some(serde_json::to_value(Vec::<serde_json::Value>::new()).unwrap()),
..ObjectProperties::default() ..ObjectProperties::default()

View file

@ -34,8 +34,8 @@ impl Reshare {
diesel::update(self) diesel::update(self)
.set(reshares::ap_url.eq(format!( .set(reshares::ap_url.eq(format!(
"{}/reshare/{}", "{}/reshare/{}",
User::get(conn, self.user_id).unwrap().compute_id(conn), User::get(conn, self.user_id).unwrap().ap_url,
Post::get(conn, self.post_id).unwrap().compute_id(conn) Post::get(conn, self.post_id).unwrap().ap_url
))) )))
.get_result::<Reshare>(conn).expect("Couldn't update AP URL"); .get_result::<Reshare>(conn).expect("Couldn't update AP URL");
} }

View file

@ -309,10 +309,10 @@ impl User {
pub fn into_activity(&self, conn: &PgConnection) -> Person { pub fn into_activity(&self, conn: &PgConnection) -> Person {
let mut actor = Person::default(); let mut actor = Person::default();
actor.object_props = ObjectProperties { actor.object_props = ObjectProperties {
id: Some(serde_json::to_value(self.compute_id(conn)).unwrap()), id: Some(serde_json::to_value(self.ap_url.clone()).unwrap()),
name: Some(serde_json::to_value(self.get_display_name()).unwrap()), name: Some(serde_json::to_value(self.get_display_name()).unwrap()),
summary: Some(serde_json::to_value(self.get_summary()).unwrap()), summary: Some(serde_json::to_value(self.get_summary()).unwrap()),
url: Some(serde_json::to_value(self.compute_id(conn)).unwrap()), url: Some(serde_json::to_value(self.ap_url.clone()).unwrap()),
..ObjectProperties::default() ..ObjectProperties::default()
}; };
actor.ap_actor_props = ApActorProperties { actor.ap_actor_props = ApActorProperties {
@ -339,12 +339,12 @@ impl User {
pub fn webfinger(&self, conn: &PgConnection) -> Webfinger { pub fn webfinger(&self, conn: &PgConnection) -> Webfinger {
Webfinger { Webfinger {
subject: format!("acct:{}@{}", self.username, self.get_instance(conn).public_domain), subject: format!("acct:{}@{}", self.username, self.get_instance(conn).public_domain),
aliases: vec![self.compute_id(conn)], aliases: vec![self.ap_url.clone()],
links: vec![ links: vec![
Link { Link {
rel: String::from("http://webfinger.net/rel/profile-page"), rel: String::from("http://webfinger.net/rel/profile-page"),
mime_type: None, mime_type: None,
href: self.compute_id(conn) href: self.ap_url.clone()
}, },
Link { Link {
rel: String::from("http://schemas.google.com/g/2010#updates-from"), rel: String::from("http://schemas.google.com/g/2010#updates-from"),
@ -354,7 +354,7 @@ impl User {
Link { Link {
rel: String::from("self"), rel: String::from("self"),
mime_type: Some(String::from("application/activity+json")), mime_type: Some(String::from("application/activity+json")),
href: self.compute_id(conn) href: self.ap_url.clone()
} }
] ]
} }
@ -411,7 +411,7 @@ impl APActor for User {
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!({
"id": self.get_key_id(conn), "id": self.get_key_id(conn),
"owner": self.compute_id(conn), "owner": self.ap_url,
"publicKeyPem": self.public_key "publicKeyPem": self.public_key
})); }));
res.insert("followers".to_string(), serde_json::Value::String(self.compute_box(conn, "followers"))); res.insert("followers".to_string(), serde_json::Value::String(self.compute_box(conn, "followers")));
@ -461,8 +461,8 @@ impl Inbox for User {
} }
impl Signer for User { impl Signer for User {
fn get_key_id(&self, conn: &PgConnection) -> String { fn get_key_id(&self, _conn: &PgConnection) -> String {
format!("{}#main-key", self.compute_id(conn)) format!("{}#main-key", self.ap_url)
} }
fn sign(&self, to_sign: String) -> Vec<u8> { fn sign(&self, to_sign: String) -> Vec<u8> {

View file

@ -206,7 +206,7 @@ fn inbox(name: String, conn: DbConn, data: String) -> String {
#[get("/@/<name>/followers", format = "application/activity+json")] #[get("/@/<name>/followers", format = "application/activity+json")]
fn ap_followers(name: String, conn: DbConn) -> ActivityPub { fn ap_followers(name: String, conn: DbConn) -> ActivityPub {
let user = User::find_local(&*conn, name).unwrap(); let user = User::find_local(&*conn, name).unwrap();
let followers = user.get_followers(&*conn).into_iter().map(|f| f.compute_id(&*conn)).collect::<Vec<String>>(); let followers = user.get_followers(&*conn).into_iter().map(|f| f.ap_url).collect::<Vec<String>>();
let json = json!({ let json = json!({
"@context": context(), "@context": context(),