Add activity_pub::Actor trait

This commit is contained in:
Bat 2018-04-23 12:57:14 +01:00
parent 474f063542
commit 74ce9aeec0
2 changed files with 29 additions and 0 deletions

28
src/activity_pub/mod.rs Normal file
View File

@ -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
)
}
}

View File

@ -15,6 +15,7 @@ use dotenv::dotenv;
use std::env; use std::env;
use rocket_contrib::Template; use rocket_contrib::Template;
mod activity_pub;
mod db_conn; mod db_conn;
mod models; mod models;
mod schema; mod schema;