From 0b32650c005e33a7eb886c9dac8af7f97cade3dd Mon Sep 17 00:00:00 2001 From: Bat Date: Fri, 18 May 2018 23:17:11 +0100 Subject: [PATCH] Remove legacy AP modules --- src/activity_pub/activity.rs | 260 ----------------------------------- src/activity_pub/mod.rs | 2 - src/activity_pub/outbox.rs | 15 -- 3 files changed, 277 deletions(-) delete mode 100644 src/activity_pub/activity.rs delete mode 100644 src/activity_pub/outbox.rs diff --git a/src/activity_pub/activity.rs b/src/activity_pub/activity.rs deleted file mode 100644 index 3e1954ad..00000000 --- a/src/activity_pub/activity.rs +++ /dev/null @@ -1,260 +0,0 @@ -use chrono; -use diesel::PgConnection; -use serde_json; - -use activity_pub::actor::Actor; -use activity_pub::object::Object; - -pub trait Activity { - fn get_id(&self) -> String; - - fn get_type(&self) -> String; - - fn serialize(&self) -> serde_json::Value; - - // fn deserialize(serde_json::Value) -> Self; -} - -#[derive(Clone)] -pub struct Accept { - id: String, - actor: serde_json::Value, - object: serde_json::Value, - date: chrono::DateTime -} - -impl Accept { - pub fn new(who: &B, what: &A, conn: &PgConnection) -> Accept { - Accept { - id: format!("{}/accept/{}/{}", who.compute_id(conn), what.get_type().to_lowercase(), what.get_id()), - actor: serde_json::Value::String(who.compute_id(conn)), - object: what.serialize(), - date: chrono::Utc::now() - } - } -} - -impl Activity for Accept { - fn get_id(&self) -> String { - self.id.clone() - } - - fn get_type(&self) -> String { - "Accept".to_string() - } - - fn serialize(&self) -> serde_json::Value { - json!({ - "type": "Accept", - "id": self.id, - "actor": self.actor, - "object": self.object, - "published": self.date.to_rfc3339() - }) - } -} - -#[derive(Clone)] -pub struct Create { - id: String, - actor: serde_json::Value, - object: serde_json::Value, - date: chrono::DateTime -} - -impl Create { - pub fn new(actor: &A, obj: &B, conn: &PgConnection) -> Create { - Create { - id: format!("{}/activity", obj.compute_id(conn)), - actor: serde_json::Value::String(actor.compute_id(conn)), - object: obj.serialize(conn), - date: chrono::Utc::now() - } - } -} - -impl Activity for Create { - fn get_id(&self) -> String { - self.id.clone() - } - - fn get_type(&self) -> String { - "Create".to_string() - } - - fn serialize(&self) -> serde_json::Value { - json!({ - "type": "Create", - "id": self.id, - "actor": self.actor, - "object": self.object, - "published": self.date.to_rfc3339(), - "to": self.object["to"], - "cc": self.object["cc"] - }) - } -} - -#[derive(Clone)] -pub struct Delete { - id: String, - actor: serde_json::Value, - object: serde_json::Value, - date: chrono::DateTime -} - -impl Delete { - pub fn new(actor: &A, obj: &B, conn: &PgConnection) -> Delete { - Delete { - id: format!("{}#delete", obj.compute_id(conn)), - actor: serde_json::Value::String(actor.compute_id(conn)), - object: serde_json::Value::String(obj.compute_id(conn)), - date: chrono::Utc::now() - } - } -} - -impl Activity for Delete { - fn get_id(&self) -> String { - self.id.clone() - } - - fn get_type(&self) -> String { - "Delete".to_string() - } - - fn serialize(&self) -> serde_json::Value { - json!({ - "type": "Delete", - "id": self.id, - "actor": self.actor, - "object": { - "type": "Tombstone", - "id": self.object - }, - "published": self.date.to_rfc3339(), - "to": self.object["to"], - "cc": self.object["cc"] - }) - } -} - -#[derive(Clone)] -pub struct Follow { - id: String, - actor: serde_json::Value, - object: serde_json::Value -} - -impl Follow { - pub fn new(follower: &A, following: &B, conn: &PgConnection) -> Follow { - Follow { - id: format!("{}/follow/{}", follower.compute_id(conn), following.compute_id(conn)), - actor: serde_json::Value::String(follower.compute_id(conn)), - object: serde_json::Value::String(following.compute_id(conn)) - } - } - - pub fn deserialize(json: serde_json::Value) -> Follow { - Follow { - id: json["id"].as_str().unwrap().to_string(), - actor: json["actor"].clone(), - object: json["object"].clone() - } - } - - pub fn get_target_id(&self) -> String { - self.object.as_str().unwrap().to_string() - } -} - -impl Activity for Follow { - fn get_id(&self) -> String { - self.id.clone() - } - - fn get_type(&self) -> String { - "Follow".to_string() - } - - fn serialize(&self) -> serde_json::Value { - json!({ - "type": "Follow", - "id": self.id, - "actor": self.actor, - "object": self.object - }) - } -} - -#[derive(Clone)] -pub struct Like { - id: String, - actor: serde_json::Value, - object: serde_json::Value -} - -impl Like { - pub fn new(actor: &A, obj: &B, conn: &PgConnection) -> Like { - Like { - id: format!("{}/like/{}", actor.compute_id(conn), obj.compute_id(conn)), - actor: serde_json::Value::String(actor.compute_id(conn)), - object: serde_json::Value::String(obj.compute_id(conn)) - } - } -} - -impl Activity for Like { - fn get_id(&self) -> String { - self.id.clone() - } - - fn get_type(&self) -> String { - "Like".to_string() - } - - fn serialize(&self) -> serde_json::Value { - json!({ - "type": "Like", - "id": self.id, - "actor": self.actor, - "object": self.object - }) - } -} - -#[derive(Clone)] -pub struct Undo { - id: String, - actor: serde_json::Value, - object: serde_json::Value -} - -impl Undo { - pub fn new(actor: &A, obj: &B, conn: &PgConnection) -> Undo { - Undo { - id: format!("{}/undo", obj.compute_id(conn)), - actor: serde_json::Value::String(actor.compute_id(conn)), - object: obj.serialize(conn) - } - } -} - -impl Activity for Undo { - fn get_id(&self) -> String { - self.id.clone() - } - - fn get_type(&self) -> String { - "Undo".to_string() - } - - fn serialize(&self) -> serde_json::Value { - json!({ - "type": "Undo", - "id": self.id, - "actor": self.actor, - "object": self.object - }) - } -} diff --git a/src/activity_pub/mod.rs b/src/activity_pub/mod.rs index f129041e..cfb38314 100644 --- a/src/activity_pub/mod.rs +++ b/src/activity_pub/mod.rs @@ -10,11 +10,9 @@ use serde_json; use self::sign::Signable; -// pub mod activity; pub mod actor; pub mod inbox; pub mod object; -// pub mod outbox; pub mod request; pub mod sign; pub mod webfinger; diff --git a/src/activity_pub/outbox.rs b/src/activity_pub/outbox.rs deleted file mode 100644 index 30d732cc..00000000 --- a/src/activity_pub/outbox.rs +++ /dev/null @@ -1,15 +0,0 @@ -use activitystreams_traits::{Activity, Object}; -use array_tool::vec::Uniq; -use diesel::PgConnection; -use reqwest::Client; -use rocket::http::Status; -use rocket::response::{Response, Responder}; -use rocket::request::Request; -use serde_json; -use std::sync::Arc; - -use activity_pub::{activity_pub, ActivityPub, context}; -use activity_pub::actor::Actor; -use activity_pub::request; -use activity_pub::sign::*; -