Plume/src/activity_pub/activity.rs

42 lines
946 B
Rust
Raw Normal View History

2018-04-29 22:23:44 +02:00
use diesel::PgConnection;
2018-04-29 19:49:56 +02:00
use serde_json;
use activity_pub::actor::Actor;
use activity_pub::object::Object;
2018-04-29 19:49:56 +02:00
#[derive(Clone)]
2018-04-29 22:23:44 +02:00
pub enum Activity {
Create(CreatePayload)
}
2018-04-29 19:49:56 +02:00
impl Activity {
pub fn serialize(&self) -> serde_json::Value {
2018-04-29 22:23:44 +02:00
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()))
2018-04-29 19:49:56 +02:00
}
}
2018-04-29 22:23:44 +02:00
#[derive(Clone)]
pub struct CreatePayload {
by: serde_json::Value,
object: serde_json::Value
}
2018-04-29 22:23:44 +02:00
impl CreatePayload {
pub fn new(by: serde_json::Value, obj: serde_json::Value) -> CreatePayload {
CreatePayload {
by: by,
object: obj
}
}
}
2018-04-29 17:40:10 +02:00