diff --git a/src/activity_pub/mod.rs b/src/activity_pub/mod.rs index 4943f58e..4f48c166 100644 --- a/src/activity_pub/mod.rs +++ b/src/activity_pub/mod.rs @@ -1,6 +1,5 @@ use activitypub::{Activity, Actor, Object, Link}; use array_tool::vec::Uniq; -use diesel::PgConnection; use reqwest::Client; use rocket::{ http::{ContentType, Status}, @@ -74,7 +73,7 @@ impl<'r, O: Object> Responder<'r> for ActivityStream { } } -pub fn broadcast(conn: &PgConnection, sender: &S, act: A, to: Vec) { +pub fn broadcast(sender: &S, act: A, to: Vec) { let boxes = to.into_iter() .map(|u| u.get_shared_inbox_url().unwrap_or(u.get_inbox_url())) .collect::>() @@ -82,14 +81,14 @@ pub fn broadcast(conn let mut act = serde_json::to_value(act).unwrap(); act["@context"] = context(); - let signed = act.sign(sender, conn); + let signed = act.sign(sender); for inbox in boxes { // TODO: run it in Sidekiq or something like that let res = Client::new() .post(&inbox[..]) .headers(request::headers()) - .header(request::signature(sender, request::headers(), conn)) + .header(request::signature(sender, request::headers())) .header(request::digest(signed.to_string())) .body(signed.to_string()) .send(); diff --git a/src/activity_pub/request.rs b/src/activity_pub/request.rs index afde1b89..e0e25171 100644 --- a/src/activity_pub/request.rs +++ b/src/activity_pub/request.rs @@ -1,5 +1,4 @@ use base64; -use diesel::PgConnection; use openssl::hash::{Hasher, MessageDigest}; use reqwest::header::{Date, Headers, UserAgent}; use std::time::SystemTime; @@ -23,7 +22,7 @@ pub fn headers() -> Headers { headers } -pub fn signature(signer: &S, headers: Headers, conn: &PgConnection) -> Signature { +pub fn signature(signer: &S, headers: Headers) -> Signature { let signed_string = headers.iter().map(|h| format!("{}: {}", h.name().to_lowercase(), h.value_string())).collect::>().join("\n"); let signed_headers = headers.iter().map(|h| h.name().to_string()).collect::>().join(" ").to_lowercase(); @@ -32,7 +31,7 @@ pub fn signature(signer: &S, headers: Headers, conn: &PgConnection) - Signature(format!( "keyId=\"{key_id}\",algorithm=\"rsa-sha256\",headers=\"{signed_headers}\",signature=\"{signature}\"", - key_id = signer.get_key_id(conn), + key_id = signer.get_key_id(), signed_headers = signed_headers, signature = sign )) diff --git a/src/activity_pub/sign.rs b/src/activity_pub/sign.rs index 6ad6275a..d71e6db2 100644 --- a/src/activity_pub/sign.rs +++ b/src/activity_pub/sign.rs @@ -1,6 +1,5 @@ use base64; use chrono::Utc; -use diesel::PgConnection; use hex; use openssl::{ pkey::PKey, @@ -24,7 +23,7 @@ pub trait Signer { } pub trait Signable { - fn sign(&mut self, creator: &T, conn: &PgConnection) -> &mut Self where T: Signer; + fn sign(&mut self, creator: &T) -> &mut Self where T: Signer; fn hash(data: String) -> String { let bytes = data.into_bytes(); @@ -33,11 +32,11 @@ pub trait Signable { } impl Signable for serde_json::Value { - fn sign(&mut self, creator: &T, conn: &PgConnection) -> &mut serde_json::Value { + fn sign(&mut self, creator: &T) -> &mut serde_json::Value { let creation_date = Utc::now().to_rfc3339(); let mut options = json!({ "type": "RsaSignature2017", - "creator": creator.get_key_id(conn), + "creator": creator.get_key_id(), "created": creation_date }); diff --git a/src/models/follows.rs b/src/models/follows.rs index 35188165..638a2578 100644 --- a/src/models/follows.rs +++ b/src/models/follows.rs @@ -44,7 +44,7 @@ impl Follow { let mut accept = Accept::default(); accept.accept_props.set_actor_link::(from.clone().into_id()).unwrap(); accept.accept_props.set_object_object(follow).unwrap(); - broadcast(conn, &*from, accept, vec![target.clone()]); + broadcast(&*from, accept, vec![target.clone()]); res } } diff --git a/src/models/users.rs b/src/models/users.rs index 63d5aec5..5190c614 100644 --- a/src/models/users.rs +++ b/src/models/users.rs @@ -401,7 +401,7 @@ impl APActor for User { fn custom_props(&self, conn: &PgConnection) -> serde_json::Map { let mut res = serde_json::Map::new(); res.insert("publicKey".to_string(), json!({ - "id": self.get_key_id(conn), + "id": self.get_key_id(), "owner": self.ap_url, "publicKeyPem": self.public_key })); diff --git a/src/routes/comments.rs b/src/routes/comments.rs index d54403cd..2bb48d5e 100644 --- a/src/routes/comments.rs +++ b/src/routes/comments.rs @@ -45,7 +45,7 @@ fn create_response(blog_name: String, slug: String, query: Option, let instance = Instance::get_local(&*conn).unwrap(); instance.received(&*conn, serde_json::to_value(new_comment.clone()).expect("JSON serialization error")); - broadcast(&*conn, &user, new_comment, user.get_followers(&*conn)); + broadcast(&user, new_comment, user.get_followers(&*conn)); Redirect::to(format!("/~/{}/{}/#comment-{}", blog_name, slug, id)) } diff --git a/src/routes/likes.rs b/src/routes/likes.rs index 216a9904..c6b0a5cd 100644 --- a/src/routes/likes.rs +++ b/src/routes/likes.rs @@ -25,11 +25,11 @@ fn create(blog: String, slug: String, user: User, conn: DbConn) -> Redirect { like.update_ap_url(&*conn); like.notify(&*conn); - broadcast(&*conn, &user, like.into_activity(&*conn), user.get_followers(&*conn)); + broadcast(&user, like.into_activity(&*conn), user.get_followers(&*conn)); } else { let like = likes::Like::find_by_user_on_post(&*conn, user.id, post.id).unwrap(); let delete_act = like.delete(&*conn); - broadcast(&*conn, &user, delete_act, user.get_followers(&*conn)); + broadcast(&user, delete_act, user.get_followers(&*conn)); } Redirect::to(uri!(super::posts::details: blog = blog, slug = slug)) diff --git a/src/routes/posts.rs b/src/routes/posts.rs index 7f5007ed..38d55633 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -119,7 +119,7 @@ fn create(blog_name: String, data: Form, user: User, conn: DbConn) } let act = post.create_activity(&*conn); - broadcast(&*conn, &user, act, user.get_followers(&*conn)); + broadcast(&user, act, user.get_followers(&*conn)); Redirect::to(uri!(details: blog = blog_name, slug = slug)) } diff --git a/src/routes/reshares.rs b/src/routes/reshares.rs index 5212faae..4166f263 100644 --- a/src/routes/reshares.rs +++ b/src/routes/reshares.rs @@ -25,11 +25,11 @@ fn create(blog: String, slug: String, user: User, conn: DbConn) -> Redirect { reshare.update_ap_url(&*conn); reshare.notify(&*conn); - broadcast(&*conn, &user, reshare.into_activity(&*conn), user.get_followers(&*conn)); + broadcast(&user, reshare.into_activity(&*conn), user.get_followers(&*conn)); } else { let reshare = Reshare::find_by_user_on_post(&*conn, user.id, post.id).unwrap(); let delete_act = reshare.delete(&*conn); - broadcast(&*conn, &user, delete_act, user.get_followers(&*conn)); + broadcast(&user, delete_act, user.get_followers(&*conn)); } Redirect::to(uri!(super::posts::details: blog = blog, slug = slug)) diff --git a/src/routes/user.rs b/src/routes/user.rs index e49df650..cc125d34 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -82,7 +82,7 @@ fn follow(name: String, conn: DbConn, user: User) -> Redirect { act.follow_props.set_object_object(user.into_activity(&*conn)).unwrap(); act.object_props.set_id_string(format!("{}/follow/{}", user.ap_url, target.ap_url)).unwrap(); - broadcast(&*conn, &user, act, vec![target]); + broadcast(&user, act, vec![target]); Redirect::to(uri!(details: name = name)) }