]> Untitled Git - lemmy.git/commitdiff
add new flag to api (#3363)
authorDomenic Horner <domenic@tgxn.net>
Tue, 27 Jun 2023 10:45:26 +0000 (18:45 +0800)
committerGitHub <noreply@github.com>
Tue, 27 Jun 2023 10:45:26 +0000 (06:45 -0400)
crates/api_common/src/community.rs
crates/api_crud/src/community/list.rs
crates/db_views_actor/src/community_view.rs

index cb92d4c2e2afd11db552e4f1b05fb0f66529a703..ff6ed1271a54963793e622e52776e95d9272a2b9 100644 (file)
@@ -76,6 +76,7 @@ pub struct CommunityResponse {
 pub struct ListCommunities {
   pub type_: Option<ListingType>,
   pub sort: Option<SortType>,
+  pub show_nsfw: Option<bool>,
   pub page: Option<i64>,
   pub limit: Option<i64>,
   pub auth: Option<Sensitive<String>>,
index a58737d990b6df32859658ff988e4140f838a8d4..d37dd2dc2cfb74ffbc22c09c9cb5a8d1330bb0b9 100644 (file)
@@ -27,12 +27,14 @@ impl PerformCrud for ListCommunities {
 
     let sort = data.sort;
     let listing_type = data.type_;
+    let show_nsfw = data.show_nsfw;
     let page = data.page;
     let limit = data.limit;
     let local_user = local_user_view.map(|l| l.local_user);
     let communities = CommunityQuery::builder()
       .pool(context.pool())
       .listing_type(listing_type)
+      .show_nsfw(show_nsfw)
       .sort(sort)
       .local_user(local_user.as_ref())
       .page(page)
index c4f5920b78122dd7b71941e984470315fb9f3461..826a0e884053a0f95d3eee25b1b3149e48ceec67 100644 (file)
@@ -126,6 +126,7 @@ pub struct CommunityQuery<'a> {
   local_user: Option<&'a LocalUser>,
   search_term: Option<String>,
   is_mod_or_admin: Option<bool>,
+  show_nsfw: Option<bool>,
   page: Option<i64>,
   limit: Option<i64>,
 }
@@ -203,8 +204,8 @@ impl<'a> CommunityQuery<'a> {
       query = query.filter(community_block::person_id.is_null());
       query = query.filter(community::nsfw.eq(false).or(local_user::show_nsfw.eq(true)));
     } else {
-      // No person in request, only show nsfw communities if show_nsfw passed into request
-      if !self.local_user.map(|l| l.show_nsfw).unwrap_or(false) {
+      // No person in request, only show nsfw communities if show_nsfw is passed into request
+      if !self.show_nsfw.unwrap_or(false) {
         query = query.filter(community::nsfw.eq(false));
       }
     }