WIP: inboxes

This commit is contained in:
Bat
2018-05-01 15:00:29 +01:00
parent 14534d1ff3
commit 03df88e186
5 changed files with 48 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
use diesel::PgConnection;
use serde_json;
use models::posts::{Post, NewPost};
pub trait Inbox {
fn received(&self, conn: &PgConnection, act: serde_json::Value);
fn save(&self, conn: &PgConnection, act: serde_json::Value) {
match act["type"].as_str().unwrap() {
"Create" => {
match act["object"]["type"].as_str().unwrap() {
"Article" => {
Post::insert(conn, NewPost {
blog_id: 0,
slug: String::from(""),
title: String::from(""),
content: act["object"]["content"].as_str().unwrap().to_string(),
published: true,
license: String::from("CC-0")
});
},
x => println!("Received a new {}, but didn't saved it", x)
}
},
x => println!("Received unknow activity type: {}", x)
}
}
}
+1
View File
@@ -5,6 +5,7 @@ use serde_json;
pub mod activity;
pub mod actor;
pub mod inbox;
pub mod object;
pub mod outbox;
pub mod sign;