mirror of https://github.com/LemmyNet/lemmy
Implement create activity
parent
f5b58bcdaf
commit
0b617377df
@ -0,0 +1,36 @@
|
||||
use crate::apub::{get_apub_protocol_string, get_following_instances};
|
||||
use crate::db::post::Post;
|
||||
use crate::db::user::User_;
|
||||
use crate::db::Crud;
|
||||
use activitystreams::activity::Create;
|
||||
use activitystreams::context;
|
||||
use diesel::PgConnection;
|
||||
use failure::Error;
|
||||
use isahc::prelude::*;
|
||||
|
||||
pub fn post_create(post: &Post, conn: &PgConnection) -> Result<(), Error> {
|
||||
let user = User_::read(conn, post.creator_id)?;
|
||||
let page = post.as_page(conn)?;
|
||||
let mut create = Create::new();
|
||||
create.object_props.set_context_xsd_any_uri(context())?;
|
||||
// TODO: seems like the create activity needs its own id (and be fetchable there)
|
||||
create
|
||||
.object_props
|
||||
.set_id(page.object_props.get_id().unwrap().to_string())?;
|
||||
create.create_props.set_actor_xsd_any_uri(user.actor_id)?;
|
||||
create.create_props.set_object_base_box(page)?;
|
||||
let json = serde_json::to_string(&create)?;
|
||||
for i in get_following_instances() {
|
||||
let inbox = format!(
|
||||
"{}://{}/federation/inbox",
|
||||
get_apub_protocol_string(),
|
||||
i.domain
|
||||
);
|
||||
let res = Request::post(inbox)
|
||||
.header("Content-Type", "application/json")
|
||||
.body(json.to_owned())?
|
||||
.send()?;
|
||||
dbg!(res);
|
||||
}
|
||||
Ok(())
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
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;
|
||||
|
||||
pub async fn 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())
|
||||
}
|
Loading…
Reference in New Issue