From 74ce9aeec0d2d55af41e6486a6881ec2f88aefbb Mon Sep 17 00:00:00 2001 From: Bat Date: Mon, 23 Apr 2018 12:57:14 +0100 Subject: [PATCH] Add activity_pub::Actor trait --- src/activity_pub/mod.rs | 28 ++++++++++++++++++++++++++++ src/main.rs | 1 + 2 files changed, 29 insertions(+) create mode 100644 src/activity_pub/mod.rs diff --git a/src/activity_pub/mod.rs b/src/activity_pub/mod.rs new file mode 100644 index 00000000..c0bfdbbd --- /dev/null +++ b/src/activity_pub/mod.rs @@ -0,0 +1,28 @@ +use models::instance::Instance; +use diesel::PgConnection; + +trait Actor { + fn get_box_prefix() -> String; + + 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!( + "https://{instance}/{prefix}/{user}/{name}", + instance = self.get_instance(conn).public_domain, + prefix = Self::get_box_prefix(), + user = self.get_actor_id(), + name = box_name + ) + } +} diff --git a/src/main.rs b/src/main.rs index bc47acac..d15f9004 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ use dotenv::dotenv; use std::env; use rocket_contrib::Template; +mod activity_pub; mod db_conn; mod models; mod schema;