Remove legacy AP modules

This commit is contained in:
Bat 2018-05-18 23:17:11 +01:00
parent d7552ba369
commit 0b32650c00
3 changed files with 0 additions and 277 deletions

View File

@ -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<chrono::Utc>
}
impl Accept {
pub fn new<A: Activity, B: Actor>(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<chrono::Utc>
}
impl Create {
pub fn new<A: Actor, B: Object>(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<chrono::Utc>
}
impl Delete {
pub fn new<A: Actor, B: Object>(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<A: Actor, B: Actor>(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<A: Actor, B: Object>(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<A: Actor, B: Object>(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
})
}
}

View File

@ -10,11 +10,9 @@ use serde_json;
use self::sign::Signable; use self::sign::Signable;
// pub mod activity;
pub mod actor; pub mod actor;
pub mod inbox; pub mod inbox;
pub mod object; pub mod object;
// pub mod outbox;
pub mod request; pub mod request;
pub mod sign; pub mod sign;
pub mod webfinger; pub mod webfinger;

View File

@ -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::*;