From f5f2aa7c599111e66cea3df8d962d96b490acb2a Mon Sep 17 00:00:00 2001 From: Bat Date: Thu, 21 Jun 2018 18:53:57 +0100 Subject: [PATCH] Get rid of the activity_pub::actor::Actor trait --- src/activity_pub/actor.rs | 28 ---------------------------- src/activity_pub/mod.rs | 1 - src/models/blogs.rs | 19 ++++--------------- src/models/users.rs | 21 +++++---------------- src/routes/user.rs | 3 +-- 5 files changed, 10 insertions(+), 62 deletions(-) delete mode 100644 src/activity_pub/actor.rs diff --git a/src/activity_pub/actor.rs b/src/activity_pub/actor.rs deleted file mode 100644 index b699652e..00000000 --- a/src/activity_pub/actor.rs +++ /dev/null @@ -1,28 +0,0 @@ -use diesel::PgConnection; - -use activity_pub::ap_url; -use models::instance::Instance; - -pub trait Actor: Sized { - fn get_box_prefix() -> &'static str; - - fn get_actor_id(&self) -> String; - - fn get_instance(&self, conn: &PgConnection) -> Instance; - - // fn compute_outbox(&self, conn: &PgConnection) -> String { - // self.compute_box(conn, "outbox") - // } - - // fn compute_inbox(&self, conn: &PgConnection) -> String { - // self.compute_box(conn, "inbox") - // } - - // fn compute_box(&self, conn: &PgConnection, box_name: &str) -> String { - // format!("{id}/{name}", id = self.compute_id(conn), name = box_name) - // } - - // fn compute_id(&self, conn: &PgConnection) -> String { - // String::new() - // } -} diff --git a/src/activity_pub/mod.rs b/src/activity_pub/mod.rs index 9903ac88..b7eb6155 100644 --- a/src/activity_pub/mod.rs +++ b/src/activity_pub/mod.rs @@ -10,7 +10,6 @@ use serde_json; use self::sign::Signable; -pub mod actor; pub mod inbox; pub mod request; pub mod sign; diff --git a/src/models/blogs.rs b/src/models/blogs.rs index f2fdd9a9..16aa13f3 100644 --- a/src/models/blogs.rs +++ b/src/models/blogs.rs @@ -18,7 +18,6 @@ use webfinger::*; use activity_pub::{ ActivityStream, Id, IntoId, - actor::{Actor as APActor}, inbox::WithInbox, sign }; @@ -61,6 +60,10 @@ impl Blog { insert!(blogs, NewBlog); get!(blogs); + pub fn get_instance(&self, conn: &PgConnection) -> Instance { + Instance::get(conn, self.instance_id).expect("Couldn't find instance") + } + pub fn find_for_author(conn: &PgConnection, author_id: i32) -> Vec { use schema::blog_authors; let author_ids = blog_authors::table.filter(blog_authors::author_id.eq(author_id)).select(blog_authors::blog_id); @@ -232,20 +235,6 @@ impl WithInbox for Blog { } } -impl APActor for Blog { - fn get_box_prefix() -> &'static str { - "~" - } - - fn get_actor_id(&self) -> String { - self.actor_id.to_string() - } - - fn get_instance(&self, conn: &PgConnection) -> Instance { - Instance::get(conn, self.instance_id).unwrap() - } -} - impl sign::Signer for Blog { fn get_key_id(&self) -> String { format!("{}#main-key", self.ap_url) diff --git a/src/models/users.rs b/src/models/users.rs index f55edce5..3cbf1df6 100644 --- a/src/models/users.rs +++ b/src/models/users.rs @@ -28,7 +28,6 @@ use webfinger::*; use BASE_URL; use activity_pub::{ ap_url, ActivityStream, Id, IntoId, - actor::{Actor as APActor}, inbox::{Inbox, WithInbox}, sign::{Signer, gen_keypair} }; @@ -92,6 +91,10 @@ impl User { find_by!(users, find_by_name, username as String, instance_id as i32); find_by!(users, find_by_ap_url, ap_url as String); + pub fn get_instance(&self, conn: &PgConnection) -> Instance { + Instance::get(conn, self.instance_id).expect("Couldn't find instance") + } + pub fn grant_admin_rights(&self, conn: &PgConnection) { diesel::update(self) .set(users::is_admin.eq(true)) @@ -316,7 +319,7 @@ impl User { actor.object_props.set_url_string(self.ap_url.clone()).expect("User::into_activity: url error"); actor.ap_actor_props.set_inbox_string(self.inbox_url.clone()).expect("User::into_activity: inbox error"); actor.ap_actor_props.set_outbox_string(self.outbox_url.clone()).expect("User::into_activity: outbox error"); - actor.ap_actor_props.set_preferred_username_string(self.get_actor_id()).expect("User::into_activity: preferredUsername error"); + actor.ap_actor_props.set_preferred_username_string(self.username.clone()).expect("User::into_activity: preferredUsername error"); let mut endpoints = Endpoint::default(); endpoints.set_shared_inbox_string(ap_url(format!("{}/inbox/", BASE_URL.as_str()))).expect("User::into_activity: endpoints.sharedInbox error"); @@ -380,20 +383,6 @@ impl<'a, 'r> FromRequest<'a, 'r> for User { } } -impl APActor for User { - fn get_box_prefix() -> &'static str { - "@" - } - - fn get_actor_id(&self) -> String { - self.username.to_string() - } - - fn get_instance(&self, conn: &PgConnection) -> Instance { - Instance::get(conn, self.instance_id).unwrap() - } -} - impl IntoId for User { fn into_id(self) -> Id { Id::new(self.ap_url.clone()) diff --git a/src/routes/user.rs b/src/routes/user.rs index cfc416f8..2f9ae0b3 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -11,8 +11,7 @@ use serde_json; use activity_pub::{ ActivityStream, broadcast, Id, IntoId, - inbox::{Inbox, Notify}, - actor::Actor + inbox::{Inbox, Notify} }; use db_conn::DbConn; use models::{