Reorganize uses
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
use diesel::PgConnection;
|
||||
use serde_json::Value;
|
||||
|
||||
use models::instance::Instance;
|
||||
|
||||
pub enum ActorType {
|
||||
Person,
|
||||
Blog
|
||||
}
|
||||
|
||||
impl ToString for ActorType {
|
||||
fn to_string(&self) -> String {
|
||||
String::from(match self {
|
||||
ActorType::Person => "Person",
|
||||
ActorType::Blog => "Blog"
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Actor {
|
||||
fn get_box_prefix() -> &'static str;
|
||||
|
||||
fn get_actor_id(&self) -> String;
|
||||
|
||||
fn get_instance(&self, conn: &PgConnection) -> Instance;
|
||||
|
||||
fn get_actor_type() -> ActorType;
|
||||
|
||||
fn as_activity_pub (&self, conn: &PgConnection) -> Value {
|
||||
json!({
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"sensitive": "as:sensitive",
|
||||
"movedTo": "as:movedTo",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"ostatus":"http://ostatus.org#",
|
||||
"atomUri":"ostatus:atomUri",
|
||||
"inReplyToAtomUri":"ostatus:inReplyToAtomUri",
|
||||
"conversation":"ostatus:conversation",
|
||||
"toot":"http://joinmastodon.org/ns#",
|
||||
"Emoji":"toot:Emoji",
|
||||
"focalPoint": {
|
||||
"@container":"@list",
|
||||
"@id":"toot:focalPoint"
|
||||
},
|
||||
"featured":"toot:featured"
|
||||
}
|
||||
],
|
||||
"id": self.compute_id(conn),
|
||||
"type": Self::get_actor_type().to_string(),
|
||||
"inbox": self.compute_inbox(conn),
|
||||
"outbox": self.compute_outbox(conn),
|
||||
"preferredUsername": self.get_actor_id(),
|
||||
"name": "",
|
||||
"summary": "",
|
||||
"url": self.compute_id(conn),
|
||||
"endpoints": {
|
||||
"sharedInbox": "https://plu.me/inbox"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
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 {
|
||||
format!(
|
||||
"https://{instance}/{prefix}/{user}",
|
||||
instance = self.get_instance(conn).public_domain,
|
||||
prefix = Self::get_box_prefix(),
|
||||
user = self.get_actor_id()
|
||||
)
|
||||
}
|
||||
}
|
||||
+1
-86
@@ -1,87 +1,2 @@
|
||||
use models::instance::Instance;
|
||||
use diesel::PgConnection;
|
||||
use serde_json::Value;
|
||||
|
||||
pub mod actor;
|
||||
pub mod webfinger;
|
||||
|
||||
pub enum ActorType {
|
||||
Person,
|
||||
Blog
|
||||
}
|
||||
|
||||
impl ToString for ActorType {
|
||||
fn to_string(&self) -> String {
|
||||
String::from(match self {
|
||||
ActorType::Person => "Person",
|
||||
ActorType::Blog => "Blog"
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Actor {
|
||||
fn get_box_prefix() -> &'static str;
|
||||
|
||||
fn get_actor_id(&self) -> String;
|
||||
|
||||
fn get_instance(&self, conn: &PgConnection) -> Instance;
|
||||
|
||||
fn get_actor_type() -> ActorType;
|
||||
|
||||
fn as_activity_pub (&self, conn: &PgConnection) -> Value {
|
||||
json!({
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"sensitive": "as:sensitive",
|
||||
"movedTo": "as:movedTo",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"ostatus":"http://ostatus.org#",
|
||||
"atomUri":"ostatus:atomUri",
|
||||
"inReplyToAtomUri":"ostatus:inReplyToAtomUri",
|
||||
"conversation":"ostatus:conversation",
|
||||
"toot":"http://joinmastodon.org/ns#",
|
||||
"Emoji":"toot:Emoji",
|
||||
"focalPoint": {
|
||||
"@container":"@list",
|
||||
"@id":"toot:focalPoint"
|
||||
},
|
||||
"featured":"toot:featured"
|
||||
}
|
||||
],
|
||||
"id": self.compute_id(conn),
|
||||
"type": Self::get_actor_type().to_string(),
|
||||
"inbox": self.compute_inbox(conn),
|
||||
"outbox": self.compute_outbox(conn),
|
||||
"preferredUsername": self.get_actor_id(),
|
||||
"name": "",
|
||||
"summary": "",
|
||||
"url": self.compute_id(conn),
|
||||
"endpoints": {
|
||||
"sharedInbox": "https://plu.me/inbox"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
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 {
|
||||
format!(
|
||||
"https://{instance}/{prefix}/{user}",
|
||||
instance = self.get_instance(conn).public_domain,
|
||||
prefix = Self::get_box_prefix(),
|
||||
user = self.get_actor_id()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use serde_json;
|
||||
use diesel::PgConnection;
|
||||
use serde_json;
|
||||
|
||||
pub trait Webfinger {
|
||||
fn webfinger_subject(&self, conn: &PgConnection) -> String;
|
||||
|
||||
Reference in New Issue
Block a user