]> Untitled Git - lemmy.git/blobdiff - crates/api_crud/src/comment/list.rs
First pass at adding comment trees. (#2362)
[lemmy.git] / crates / api_crud / src / comment / list.rs
index 87262dce7629f89508713325996e64656c04693d..998acc038167390f452f3df0dfe94f592e517519 100644 (file)
@@ -10,7 +10,10 @@ use lemmy_api_common::{
   },
 };
 use lemmy_apub::{fetcher::resolve_actor_identifier, objects::community::ApubCommunity};
-use lemmy_db_schema::{source::community::Community, traits::DeleteableOrRemoveable};
+use lemmy_db_schema::{
+  source::{comment::Comment, community::Community},
+  traits::{Crud, DeleteableOrRemoveable},
+};
 use lemmy_db_views::comment_view::CommentQueryBuilder;
 use lemmy_utils::{error::LemmyError, ConnectionId};
 use lemmy_websocket::LemmyContext;
@@ -49,16 +52,34 @@ impl PerformCrud for GetComments {
       None
     };
     let sort = data.sort;
+    let max_depth = data.max_depth;
     let saved_only = data.saved_only;
     let page = data.page;
     let limit = data.limit;
+    let parent_id = data.parent_id;
+
+    // If a parent_id is given, fetch the comment to get the path
+    let parent_path = if let Some(parent_id) = parent_id {
+      Some(
+        blocking(context.pool(), move |conn| Comment::read(conn, parent_id))
+          .await??
+          .path,
+      )
+    } else {
+      None
+    };
+
+    let post_id = data.post_id;
     let mut comments = blocking(context.pool(), move |conn| {
       CommentQueryBuilder::create(conn)
         .listing_type(listing_type)
         .sort(sort)
+        .max_depth(max_depth)
         .saved_only(saved_only)
         .community_id(community_id)
         .community_actor_id(community_actor_id)
+        .parent_path(parent_path)
+        .post_id(post_id)
         .my_person_id(person_id)
         .show_bot_accounts(show_bot_accounts)
         .page(page)