Actually serialize posts in outbox

This commit is contained in:
Bat
2018-04-30 17:50:35 +01:00
parent bde25478e5
commit 0fd63eb886
4 changed files with 40 additions and 9 deletions
+9 -5
View File
@@ -1,3 +1,4 @@
use chrono;
use diesel::PgConnection;
use serde_json;
@@ -13,28 +14,31 @@ impl Activity {
match self {
Activity::Create(data) => json!({
"type": "Create",
"by": data.by,
"object": data.object
"actor": data.by,
"object": data.object,
"published": data.date.to_rfc3339()
})
}
}
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()))
Activity::Create(CreatePayload::new(serde_json::Value::String(by.compute_id(conn)), obj.serialize(conn)))
}
}
#[derive(Clone)]
pub struct CreatePayload {
by: serde_json::Value,
object: serde_json::Value
object: serde_json::Value,
date: chrono::DateTime<chrono::Utc>
}
impl CreatePayload {
pub fn new(by: serde_json::Value, obj: serde_json::Value) -> CreatePayload {
CreatePayload {
by: by,
object: obj
object: obj,
date: chrono::Utc::now()
}
}
}
+1
View File
@@ -13,6 +13,7 @@ pub mod webfinger;
pub type ActivityPub = Content<Json>;
pub const CONTEXT_URL: &'static str = "https://www.w3.org/ns/activitystreams";
pub const PUBLIC_VISIBILTY: &'static str = "https://www.w3.org/ns/activitystreams#Public";
pub fn context() -> serde_json::Value {
json!([
+2 -1
View File
@@ -1,9 +1,10 @@
use diesel::PgConnection;
use serde_json;
use activity_pub::actor::Actor;
pub trait Object {
fn serialize(&self) -> serde_json::Value;
fn serialize(&self, conn: &PgConnection) -> serde_json::Value;
}
pub trait Attribuable {