From: Domenic Horner Date: Tue, 27 Jun 2023 10:45:26 +0000 (+0800) Subject: add new flag to api (#3363) X-Git-Url: http://these/git/readmes/static/git-logo.png?a=commitdiff_plain;h=d1d90af0eb749ad79bc46ee81717e7166936ea89;p=lemmy.git add new flag to api (#3363) --- diff --git a/crates/api_common/src/community.rs b/crates/api_common/src/community.rs index cb92d4c2..ff6ed127 100644 --- a/crates/api_common/src/community.rs +++ b/crates/api_common/src/community.rs @@ -76,6 +76,7 @@ pub struct CommunityResponse { pub struct ListCommunities { pub type_: Option, pub sort: Option, + pub show_nsfw: Option, pub page: Option, pub limit: Option, pub auth: Option>, diff --git a/crates/api_crud/src/community/list.rs b/crates/api_crud/src/community/list.rs index a58737d9..d37dd2dc 100644 --- a/crates/api_crud/src/community/list.rs +++ b/crates/api_crud/src/community/list.rs @@ -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) diff --git a/crates/db_views_actor/src/community_view.rs b/crates/db_views_actor/src/community_view.rs index c4f5920b..826a0e88 100644 --- a/crates/db_views_actor/src/community_view.rs +++ b/crates/db_views_actor/src/community_view.rs @@ -126,6 +126,7 @@ pub struct CommunityQuery<'a> { local_user: Option<&'a LocalUser>, search_term: Option, is_mod_or_admin: Option, + show_nsfw: Option, page: Option, limit: Option, } @@ -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)); } }