]> Untitled Git - lemmy.git/commitdiff
Adding listing_type to search.
authorDessalines <tyhou13@gmx.com>
Fri, 9 Apr 2021 20:35:51 +0000 (16:35 -0400)
committerDessalines <tyhou13@gmx.com>
Fri, 23 Apr 2021 06:13:32 +0000 (02:13 -0400)
crates/api/src/site.rs
crates/api_common/src/site.rs
crates/api_crud/src/comment/read.rs
crates/db_views/src/comment_view.rs

index a6f09f59ba896242c87b30728c52cb02d5683cfa..481f99687c35c4d0fc5ed9ca541bc303c034bc82 100644 (file)
@@ -13,7 +13,7 @@ use lemmy_api_common::{
   user_show_nsfw,
 };
 use lemmy_apub::fetcher::search::search_by_apub_id;
-use lemmy_db_queries::{source::site::Site_, Crud, SearchType, SortType};
+use lemmy_db_queries::{source::site::Site_, Crud, ListingType, SearchType, SortType};
 use lemmy_db_schema::source::{moderator::*, site::Site};
 use lemmy_db_views::{
   comment_view::CommentQueryBuilder,
@@ -144,8 +144,6 @@ impl Perform for Search {
 
     let person_id = local_user_view.map(|u| u.person.id);
 
-    let type_ = SearchType::from_str(&data.type_)?;
-
     let mut posts = Vec::new();
     let mut comments = Vec::new();
     let mut communities = Vec::new();
@@ -157,9 +155,10 @@ impl Perform for Search {
     let page = data.page;
     let limit = data.limit;
     let sort = SortType::from_str(&data.sort)?;
+    let type_ = SearchType::from_str(&data.type_)?;
+    let listing_type = ListingType::from_str(&data.listing_type)?;
     let community_id = data.community_id;
     let community_name = data.community_name.to_owned();
-    let community_name_2 = data.community_name.to_owned();
     let creator_id = data.creator_id;
     match type_ {
       SearchType::Posts => {
@@ -168,6 +167,8 @@ impl Perform for Search {
             .sort(&sort)
             .show_nsfw(show_nsfw)
             .show_bot_accounts(show_bot_accounts)
+            .listing_type(&listing_type)
+            .show_nsfw(true)
             .community_id(community_id)
             .community_name(community_name)
             .creator_id(creator_id)
@@ -183,6 +184,7 @@ impl Perform for Search {
         comments = blocking(context.pool(), move |conn| {
           CommentQueryBuilder::create(&conn)
             .sort(&sort)
+            .listing_type(&listing_type)
             .search_term(q)
             .show_bot_accounts(show_bot_accounts)
             .community_id(community_id)
@@ -199,6 +201,7 @@ impl Perform for Search {
         communities = blocking(context.pool(), move |conn| {
           CommunityQueryBuilder::create(conn)
             .sort(&sort)
+            .listing_type(&listing_type)
             .search_term(q)
             .my_person_id(person_id)
             .page(page)
@@ -224,6 +227,8 @@ impl Perform for Search {
             .sort(&sort)
             .show_nsfw(show_nsfw)
             .show_bot_accounts(show_bot_accounts)
+            .listing_type(&listing_type)
+            .show_nsfw(true)
             .community_id(community_id)
             .community_name(community_name)
             .creator_id(creator_id)
@@ -237,14 +242,17 @@ impl Perform for Search {
 
         let q = data.q.to_owned();
         let sort = SortType::from_str(&data.sort)?;
+        let listing_type = ListingType::from_str(&data.listing_type)?;
+        let community_name = data.community_name.to_owned();
 
         comments = blocking(context.pool(), move |conn| {
           CommentQueryBuilder::create(conn)
             .sort(&sort)
+            .listing_type(&listing_type)
             .search_term(q)
             .show_bot_accounts(show_bot_accounts)
             .community_id(community_id)
-            .community_name(community_name_2)
+            .community_name(community_name)
             .creator_id(creator_id)
             .my_person_id(person_id)
             .page(page)
@@ -255,10 +263,12 @@ impl Perform for Search {
 
         let q = data.q.to_owned();
         let sort = SortType::from_str(&data.sort)?;
+        let listing_type = ListingType::from_str(&data.listing_type)?;
 
         communities = blocking(context.pool(), move |conn| {
           CommunityQueryBuilder::create(conn)
             .sort(&sort)
+            .listing_type(&listing_type)
             .search_term(q)
             .my_person_id(person_id)
             .page(page)
@@ -286,6 +296,8 @@ impl Perform for Search {
             .sort(&sort)
             .show_nsfw(show_nsfw)
             .show_bot_accounts(show_bot_accounts)
+            .listing_type(&listing_type)
+            .show_nsfw(true)
             .my_person_id(person_id)
             .community_id(community_id)
             .community_name(community_name)
index 6d3ebf63e9369798911f89e9655c3877143081c9..b244b58a9ddcac03532a3e61374c35d7954c5cb4 100644 (file)
@@ -27,6 +27,7 @@ pub struct Search {
   pub community_name: Option<String>,
   pub creator_id: Option<PersonId>,
   pub sort: String,
+  pub listing_type: String,
   pub page: Option<i64>,
   pub limit: Option<i64>,
   pub auth: Option<String>,
index 4d144382089688aa2b1a2eeb137941b4dad884b1..70fe964c38762ed904003f766821f10cab71eb42 100644 (file)
@@ -27,7 +27,7 @@ impl PerformCrud for GetComments {
     let show_bot_accounts = user_show_bot_accounts(&local_user_view);
     let person_id = local_user_view.map(|u| u.person.id);
 
-    let type_ = ListingType::from_str(&data.type_)?;
+    let listing_type = ListingType::from_str(&data.type_)?;
     let sort = SortType::from_str(&data.sort)?;
 
     let community_id = data.community_id;
@@ -37,7 +37,7 @@ impl PerformCrud for GetComments {
     let limit = data.limit;
     let comments = blocking(context.pool(), move |conn| {
       CommentQueryBuilder::create(conn)
-        .listing_type(type_)
+        .listing_type(&listing_type)
         .sort(&sort)
         .saved_only(saved_only)
         .community_id(community_id)
index b85b1c77a654d38a544458e1d9890f989ab88d78..cf12442f60175be990367837312ba608bbbd55e8 100644 (file)
@@ -172,7 +172,7 @@ impl CommentView {
 
 pub struct CommentQueryBuilder<'a> {
   conn: &'a PgConnection,
-  listing_type: ListingType,
+  listing_type: &'a ListingType,
   sort: &'a SortType,
   community_id: Option<CommunityId>,
   community_name: Option<String>,
@@ -192,7 +192,7 @@ impl<'a> CommentQueryBuilder<'a> {
   pub fn create(conn: &'a PgConnection) -> Self {
     CommentQueryBuilder {
       conn,
-      listing_type: ListingType::All,
+      listing_type: &ListingType::All,
       sort: &SortType::New,
       community_id: None,
       community_name: None,
@@ -209,7 +209,7 @@ impl<'a> CommentQueryBuilder<'a> {
     }
   }
 
-  pub fn listing_type(mut self, listing_type: ListingType) -> Self {
+  pub fn listing_type(mut self, listing_type: &'a ListingType) -> Self {
     self.listing_type = listing_type;
     self
   }