summaryrefslogtreecommitdiffstats
path: root/server/src/apub/inbox.rs
blob: 8b6504a7f56b133cdb09927873ce7c86ac3bc74a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use crate::db::post::{Post, PostForm};
use crate::db::Crud;
use activitystreams::activity::Create;
use activitystreams::object::Page;
use actix_web::{web, HttpResponse};
use diesel::r2d2::{ConnectionManager, Pool};
use diesel::PgConnection;
use failure::Error;

// TODO: need a proper actor that has this inbox

pub async fn create_inbox(
  create: web::Json<Create>,
  db: web::Data<Pool<ConnectionManager<PgConnection>>>,
) -> Result<HttpResponse, Error> {
  let page = create
    .create_props
    .get_object_base_box()
    .unwrap()
    .to_owned()
    .to_concrete::<Page>()?;
  let post = PostForm::from_page(&page, &db.get().unwrap())?;
  Post::create(&db.get().unwrap(), &post)?;
  // TODO: send the new post out via websocket
  dbg!(&post);
  Ok(HttpResponse::Ok().finish())
}