diff --git a/server/lemmy_api_structs/src/comment.rs b/server/lemmy_api_structs/src/comment.rs index 906c39965..4c18a3dec 100644 --- a/server/lemmy_api_structs/src/comment.rs +++ b/server/lemmy_api_structs/src/comment.rs @@ -68,6 +68,7 @@ pub struct GetComments { pub page: Option, pub limit: Option, pub community_id: Option, + pub community_name: Option, pub auth: Option, } diff --git a/server/lemmy_db/src/comment_view.rs b/server/lemmy_db/src/comment_view.rs index d7e5c08d0..843c026b3 100644 --- a/server/lemmy_db/src/comment_view.rs +++ b/server/lemmy_db/src/comment_view.rs @@ -132,6 +132,7 @@ pub struct CommentQueryBuilder<'a> { listing_type: ListingType, sort: &'a SortType, for_community_id: Option, + for_community_name: Option, for_post_id: Option, for_creator_id: Option, search_term: Option, @@ -153,6 +154,7 @@ impl<'a> CommentQueryBuilder<'a> { listing_type: ListingType::All, sort: &SortType::New, for_community_id: None, + for_community_name: None, for_post_id: None, for_creator_id: None, search_term: None, @@ -188,6 +190,11 @@ impl<'a> CommentQueryBuilder<'a> { self } + pub fn for_community_name>(mut self, for_community_name: T) -> Self { + self.for_community_name = for_community_name.get_optional(); + self + } + pub fn search_term>(mut self, search_term: T) -> Self { self.search_term = search_term.get_optional(); self @@ -233,6 +240,10 @@ impl<'a> CommentQueryBuilder<'a> { query = query.filter(community_id.eq(for_community_id)); } + if let Some(for_community_name) = self.for_community_name { + query = query.filter(community_name.eq(for_community_name)); + } + if let Some(for_post_id) = self.for_post_id { query = query.filter(post_id.eq(for_post_id)); }; diff --git a/server/lemmy_db/src/post_view.rs b/server/lemmy_db/src/post_view.rs index 3d3afb709..da93ecdae 100644 --- a/server/lemmy_db/src/post_view.rs +++ b/server/lemmy_db/src/post_view.rs @@ -1,7 +1,7 @@ use super::post_view::post_fast_view::BoxedQuery; use crate::{fuzzy_search, limit_and_offset, ListingType, MaybeOptional, SortType}; use diesel::{dsl::*, pg::Pg, result::Error, *}; -use serde::{Serialize}; +use serde::Serialize; // The faked schema since diesel doesn't do views table! { diff --git a/server/src/api/comment.rs b/server/src/api/comment.rs index f0e56810e..e7b4080eb 100644 --- a/server/src/api/comment.rs +++ b/server/src/api/comment.rs @@ -674,6 +674,7 @@ impl Perform for GetComments { let sort = SortType::from_str(&data.sort)?; let community_id = data.community_id; + let community_name = data.community_name.to_owned(); let page = data.page; let limit = data.limit; let comments = blocking(context.pool(), move |conn| { @@ -681,6 +682,7 @@ impl Perform for GetComments { .listing_type(type_) .sort(&sort) .for_community_id(community_id) + .for_community_name(community_name) .my_user_id(user_id) .page(page) .limit(limit)