From d9657b24a7a9528124e21e92ab7aaae1a05e4c37 Mon Sep 17 00:00:00 2001 From: Felix Date: Thu, 9 Apr 2020 21:26:22 +0200 Subject: [PATCH] Minor code cleanup --- server/src/api/post.rs | 5 +++-- server/src/apub/activities.rs | 8 ++++---- server/src/apub/inbox.rs | 4 +++- server/src/routes/federation.rs | 6 ++++-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/server/src/api/post.rs b/server/src/api/post.rs index 7e7126a2..e0053fe8 100644 --- a/server/src/api/post.rs +++ b/server/src/api/post.rs @@ -107,7 +107,8 @@ impl Perform for Oper { } // Check for a site ban - if UserView::read(&conn, user_id)?.banned { + let user = User_::read(&conn, user_id)?; + if user.banned { return Err(APIError::err("site_ban").into()); } @@ -154,7 +155,7 @@ impl Perform for Oper { Err(_e) => return Err(APIError::err("couldnt_create_post").into()), }; - post_create(&inserted_post, conn)?; + post_create(&inserted_post, &user, conn)?; // They like their own post by default let like_form = PostLikeForm { diff --git a/server/src/apub/activities.rs b/server/src/apub/activities.rs index 81a624b0..3968a8b0 100644 --- a/server/src/apub/activities.rs +++ b/server/src/apub/activities.rs @@ -1,15 +1,13 @@ 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)?; +pub fn post_create(post: &Post, creator: &User_, conn: &PgConnection) -> Result<(), Error> { let page = post.as_page(conn)?; let mut create = Create::new(); create.object_props.set_context_xsd_any_uri(context())?; @@ -17,7 +15,9 @@ pub fn post_create(post: &Post, conn: &PgConnection) -> Result<(), Error> { 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_actor_xsd_any_uri(creator.actor_id.to_owned())?; create.create_props.set_object_base_box(page)?; let json = serde_json::to_string(&create)?; for i in get_following_instances() { diff --git a/server/src/apub/inbox.rs b/server/src/apub/inbox.rs index 53da497f..8b6504a7 100644 --- a/server/src/apub/inbox.rs +++ b/server/src/apub/inbox.rs @@ -7,7 +7,9 @@ use diesel::r2d2::{ConnectionManager, Pool}; use diesel::PgConnection; use failure::Error; -pub async fn inbox( +// TODO: need a proper actor that has this inbox + +pub async fn create_inbox( create: web::Json, db: web::Data>>, ) -> Result { diff --git a/server/src/routes/federation.rs b/server/src/routes/federation.rs index 64cc5a81..c85d9d49 100644 --- a/server/src/routes/federation.rs +++ b/server/src/routes/federation.rs @@ -10,8 +10,10 @@ pub fn config(cfg: &mut web::ServiceConfig) { "/federation/communities", web::get().to(apub::community::get_apub_community_list), ) - // TODO: need a proper actor that has this inbox - .route("/federation/inbox", web::post().to(apub::inbox::inbox)) + .route( + "/federation/inbox", + web::post().to(apub::inbox::create_inbox), + ) .route( "/federation/c/{community_name}", web::get().to(apub::community::get_apub_community_http),