Add activity_pub::Actor trait
This commit is contained in:
		
							parent
							
								
									474f063542
								
							
						
					
					
						commit
						74ce9aeec0
					
				
							
								
								
									
										28
									
								
								src/activity_pub/mod.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/activity_pub/mod.rs
									
									
									
									
									
										Normal 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
 | 
			
		||||
        )
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -15,6 +15,7 @@ use dotenv::dotenv;
 | 
			
		||||
use std::env;
 | 
			
		||||
use rocket_contrib::Template;
 | 
			
		||||
 | 
			
		||||
mod activity_pub;
 | 
			
		||||
mod db_conn;
 | 
			
		||||
mod models;
 | 
			
		||||
mod schema;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user