Start filling user outbox

This commit is contained in:
Bat
2018-04-29 21:23:44 +01:00
parent dd9e845e66
commit bde25478e5
6 changed files with 56 additions and 21 deletions
+22 -10
View File
@@ -1,26 +1,38 @@
use diesel::PgConnection;
use serde_json;
use activity_pub::actor::Actor;
use activity_pub::object::Object;
#[derive(Clone)]
pub struct Activity {}
pub enum Activity {
Create(CreatePayload)
}
impl Activity {
pub fn serialize(&self) -> serde_json::Value {
json!({})
match self {
Activity::Create(data) => json!({
"type": "Create",
"by": data.by,
"object": data.object
})
}
}
pub fn create<T: Object, U: Actor>(by: &U, obj: T, conn: &PgConnection) -> Activity {
Activity::Create(CreatePayload::new(serde_json::Value::String(by.compute_id(conn)), obj.serialize()))
}
}
#[allow(dead_code)]
pub struct Create<'a, T, U> where T: Actor + 'static, U: Object {
by: &'a T,
object: U
#[derive(Clone)]
pub struct CreatePayload {
by: serde_json::Value,
object: serde_json::Value
}
impl<'a, T: Actor, U: Object> Create<'a, T, U> {
#[allow(dead_code)]
pub fn new(by: &T, obj: U) -> Create<T, U> {
Create {
impl CreatePayload {
pub fn new(by: serde_json::Value, obj: serde_json::Value) -> CreatePayload {
CreatePayload {
by: by,
object: obj
}
+5 -5
View File
@@ -1,7 +1,7 @@
use diesel::PgConnection;
use activity_pub::{activity_pub, ActivityPub, context};
use activity_pub::activity::Create;
// use activity_pub::activity::Create;
use activity_pub::object::{Attribuable, Object};
use models::instance::Instance;
@@ -66,8 +66,8 @@ pub trait Actor {
)
}
fn create<T>(&self, obj: T) -> Create<Self, T> where T: Object + Attribuable, Self: Actor + Sized {
obj.set_attribution::<Self>(self);
Create::<Self, T>::new(self, obj)
}
// fn create<T>(&self, obj: T) -> Create<Self, T> where T: Object + Attribuable, Self: Actor + Sized {
// obj.set_attribution::<Self>(self);
// Create::<Self, T>::new(self, obj)
// }
}
+5 -1
View File
@@ -1,6 +1,10 @@
use serde_json;
use activity_pub::actor::Actor;
pub trait Object {}
pub trait Object {
fn serialize(&self) -> serde_json::Value;
}
pub trait Attribuable {
fn set_attribution<T>(&self, by: &T) where T: Actor;