diff --git a/src/activity_pub/activity.rs b/src/activity_pub/activity.rs index 6e0b47c..f3f77d9 100644 --- a/src/activity_pub/activity.rs +++ b/src/activity_pub/activity.rs @@ -6,7 +6,7 @@ use std::str::FromStr; use activity_pub::actor::Actor; use activity_pub::object::Object; -pub trait Activity: ActivityClone { +pub trait Activity { fn get_id(&self) -> String; fn serialize(&self) -> serde_json::Value; @@ -14,26 +14,6 @@ pub trait Activity: ActivityClone { // fn deserialize(serde_json::Value) -> Self; } -trait ActivityClone { - fn clone_box(&self) -> Box; -} - -impl ActivityClone for T -where - T: 'static + Activity + Clone, -{ - fn clone_box(&self) -> Box { - Box::new(self.clone()) - } -} - -// We can now implement Clone manually by forwarding to clone_box. -impl Clone for Box { - fn clone(&self) -> Box { - self.clone_box() - } -} - #[derive(Clone)] pub struct Accept { id: String, diff --git a/src/activity_pub/outbox.rs b/src/activity_pub/outbox.rs index 9aa891d..2902007 100644 --- a/src/activity_pub/outbox.rs +++ b/src/activity_pub/outbox.rs @@ -3,19 +3,20 @@ use rocket::http::Status; use rocket::response::{Response, Responder}; use rocket::request::Request; use serde_json; +use std::sync::Arc; use activity_pub::{activity_pub, ActivityPub, context}; use activity_pub::activity::Activity; use activity_pub::actor::Actor; use models::users::User; -pub struct Outbox where A: Activity + Clone { +pub struct Outbox { id: String, - items: Vec> + items: Vec> } -impl Outbox { - pub fn new(id: String, items: Vec>) -> Outbox { +impl Outbox { + pub fn new(id: String, items: Vec>) -> Outbox { Outbox { id: id, items: items @@ -34,7 +35,7 @@ impl Outbox { } } -impl<'r, A: Activity + Clone + 'static> Responder<'r> for Outbox { +impl<'r> Responder<'r> for Outbox { fn respond_to(self, request: &Request) -> Result, Status> { self.serialize().respond_to(request) } diff --git a/src/models/blogs.rs b/src/models/blogs.rs index 0957c43..29b528f 100644 --- a/src/models/blogs.rs +++ b/src/models/blogs.rs @@ -1,5 +1,6 @@ use chrono::NaiveDateTime; use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection}; +use std::sync::Arc; use activity_pub::activity::Activity; use activity_pub::actor::{Actor, ActorType}; @@ -78,11 +79,11 @@ impl Blog { } } - pub fn outbox(&self, conn: &PgConnection) -> Outbox { + pub fn outbox(&self, conn: &PgConnection) -> Outbox { Outbox::new(self.compute_outbox(conn), self.get_activities(conn)) } - fn get_activities(&self, _conn: &PgConnection) -> Vec> { + fn get_activities(&self, _conn: &PgConnection) -> Vec> { vec![] } } diff --git a/src/models/users.rs b/src/models/users.rs index 8a57ac9..84ad958 100644 --- a/src/models/users.rs +++ b/src/models/users.rs @@ -8,6 +8,7 @@ use reqwest::mime::Mime; use rocket::request::{self, FromRequest, Request}; use rocket::outcome::IntoOutcome; use serde_json; +use std::sync::Arc; use url::Url; use BASE_URL; @@ -184,16 +185,16 @@ impl User { } } - pub fn outbox(&self, conn: &PgConnection) -> Outbox { + pub fn outbox(&self, conn: &PgConnection) -> Outbox { Outbox::new(self.compute_outbox(conn), self.get_activities(conn)) } - fn get_activities(&self, conn: &PgConnection) -> Vec> { + fn get_activities(&self, conn: &PgConnection) -> Vec> { use schema::posts; use schema::post_authors; let posts_by_self = PostAuthor::belonging_to(self).select(post_authors::post_id); let posts = posts::table.filter(posts::id.eq(any(posts_by_self))).load::(conn).unwrap(); - posts.into_iter().map(|p| Box::new(Create::new(self, &p, conn)) as Box).collect::>>() + posts.into_iter().map(|p| Arc::new(Create::new(self, &p, conn)) as Arc).collect::>>() } pub fn get_followers(&self, conn: &PgConnection) -> Vec { diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index 4bc619b..ace2597 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -4,7 +4,6 @@ use rocket_contrib::Template; use std::collections::HashMap; use activity_pub::ActivityPub; -use activity_pub::activity::Activity; use activity_pub::actor::Actor; use activity_pub::outbox::Outbox; use db_conn::DbConn; @@ -58,7 +57,7 @@ fn create(conn: DbConn, data: Form, user: User) -> Redirect { } #[get("/~//outbox")] -fn outbox(name: String, conn: DbConn) -> Outbox { +fn outbox(name: String, conn: DbConn) -> Outbox { let blog = Blog::find_by_actor_id(&*conn, name).unwrap(); blog.outbox(&*conn) }