Shared inbox endpoint

This commit is contained in:
Bat 2018-05-13 18:39:18 +01:00
parent 91b19bccb5
commit dfab0290e4
4 changed files with 21 additions and 1 deletions

View File

@ -12,7 +12,7 @@ use models::likes::*;
use models::posts::*;
use models::users::User;
pub trait Inbox: Actor + Sized {
pub trait Inbox {
fn received(&self, conn: &PgConnection, act: serde_json::Value);
fn save(&self, conn: &PgConnection, act: serde_json::Value) {

View File

@ -67,6 +67,7 @@ fn main() {
routes::instance::index,
routes::instance::configure,
routes::instance::post_config,
routes::instance::shared_inbox,
routes::notifications::notifications,

View File

@ -1,7 +1,9 @@
use chrono::NaiveDateTime;
use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection};
use serde_json;
use std::iter::Iterator;
use activity_pub::inbox::Inbox;
use models::users::User;
use schema::{instances, users};
@ -81,3 +83,11 @@ impl Instance {
.len() > 0
}
}
impl Inbox for Instance {
fn received(&self, conn: &PgConnection, act: serde_json::Value) {
self.save(conn, act.clone());
// TODO: add to stream, or whatever needs to be done
}
}

View File

@ -4,6 +4,7 @@ use rocket_contrib::Template;
use serde_json;
use BASE_URL;
use activity_pub::inbox::Inbox;
use db_conn::DbConn;
use models::posts::Post;
use models::users::User;
@ -65,3 +66,11 @@ fn post_config(conn: DbConn, data: Form<NewInstanceForm>) -> Redirect {
Redirect::to("/users/new")
}
}
#[post("/inbox", data = "<data>")]
fn shared_inbox(conn: DbConn, data: String) -> String {
let act: serde_json::Value = serde_json::from_str(&data[..]).unwrap();
let instance = Instance::get_local(&*conn).unwrap();
instance.received(&*conn, act);
String::from("")
}