]> Untitled Git - lemmy.git/commitdiff
Minor code cleanup
authorFelix <me@nutomic.com>
Thu, 9 Apr 2020 19:26:22 +0000 (21:26 +0200)
committerFelix <me@nutomic.com>
Thu, 9 Apr 2020 19:26:22 +0000 (21:26 +0200)
server/src/api/post.rs
server/src/apub/activities.rs
server/src/apub/inbox.rs
server/src/routes/federation.rs

index 7e7126a2f64c7039880660aa0c4fd1067d33865c..e0053fe8192f85805bcf96479ae999dc47e56d1a 100644 (file)
@@ -107,7 +107,8 @@ impl Perform<PostResponse> for Oper<CreatePost> {
     }
 
     // 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<PostResponse> for Oper<CreatePost> {
       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 {
index 81a624b05281bee54043945d11a3fb24ac3ac056..3968a8b006bdf35261a29fd349609a5e50e59f36 100644 (file)
@@ -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() {
index 53da497f21bde6424dacd3fb46cb6f87b14eb056..8b6504a7f56b133cdb09927873ce7c86ac3bc74a 100644 (file)
@@ -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<Create>,
   db: web::Data<Pool<ConnectionManager<PgConnection>>>,
 ) -> Result<HttpResponse, Error> {
index 64cc5a814dfe2f91e26ec7c367375fff7de3265d..c85d9d4969f8dc196f456d71d643f85b3cdc7f57 100644 (file)
@@ -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),