From ca0e3829f07d21887ec1ba783dd972a790b9f102 Mon Sep 17 00:00:00 2001 From: Sun Wukong Date: Mon, 21 Feb 2022 15:22:04 -0600 Subject: [PATCH 1/2] Show nsfw communities in logged in and you've enabled nsfw in your profile atleast --- crates/db_views_actor/src/community_view.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/db_views_actor/src/community_view.rs b/crates/db_views_actor/src/community_view.rs index 50ca6f4dd0..16fc1d72df 100644 --- a/crates/db_views_actor/src/community_view.rs +++ b/crates/db_views_actor/src/community_view.rs @@ -6,7 +6,7 @@ use lemmy_db_schema::{ fuzzy_search, limit_and_offset, newtypes::{CommunityId, PersonId}, - schema::{community, community_aggregates, community_block, community_follower}, + schema::{community, community_aggregates, community_block, community_follower, local_user}, source::{ community::{Community, CommunityFollower, CommunitySafe}, community_block::CommunityBlock, @@ -167,6 +167,7 @@ impl<'a> CommunityQueryBuilder<'a> { let mut query = community::table .inner_join(community_aggregates::table) + .left_join(local_user::table.on(local_user::person_id.eq(person_id_join))) .left_join( community_follower::table.on( community::id @@ -231,11 +232,16 @@ impl<'a> CommunityQueryBuilder<'a> { .then_order_by(community_aggregates::published.desc()) } }; - - if !self.show_nsfw.unwrap_or(false) { + if !self.show_nsfw.unwrap_or(false) && person_id_join == PersonId(-1) { query = query.filter(community::nsfw.eq(false)); }; + // Show nsfw communities if show_nsfw is selected in a user's profile + if person_id_join != PersonId(-1) { + // Passed in person object + query = query.filter(community::nsfw.eq(false).or(local_user::show_nsfw.eq(true))); + } + if let Some(listing_type) = self.listing_type { query = match listing_type { ListingType::Subscribed => query.filter(community_follower::person_id.is_not_null()), // TODO could be this: and(community_follower::person_id.eq(person_id_join)), From 888b4a869fe1c10bd078d52f0c2bde43c854b854 Mon Sep 17 00:00:00 2001 From: Sun Wukong Date: Sun, 27 Feb 2022 08:55:29 -0600 Subject: [PATCH 2/2] Reuse existing user check --- crates/db_views_actor/src/community_view.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/crates/db_views_actor/src/community_view.rs b/crates/db_views_actor/src/community_view.rs index 16fc1d72df..a7b711b437 100644 --- a/crates/db_views_actor/src/community_view.rs +++ b/crates/db_views_actor/src/community_view.rs @@ -232,15 +232,6 @@ impl<'a> CommunityQueryBuilder<'a> { .then_order_by(community_aggregates::published.desc()) } }; - if !self.show_nsfw.unwrap_or(false) && person_id_join == PersonId(-1) { - query = query.filter(community::nsfw.eq(false)); - }; - - // Show nsfw communities if show_nsfw is selected in a user's profile - if person_id_join != PersonId(-1) { - // Passed in person object - query = query.filter(community::nsfw.eq(false).or(local_user::show_nsfw.eq(true))); - } if let Some(listing_type) = self.listing_type { query = match listing_type { @@ -250,9 +241,15 @@ impl<'a> CommunityQueryBuilder<'a> { }; } - // Don't show blocked communities + // Don't show blocked communities or nsfw communities if not enabled in profile if self.my_person_id.is_some() { 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.show_nsfw.unwrap_or(false) { + query = query.filter(community::nsfw.eq(false)); + } } let (limit, offset) = limit_and_offset(self.page, self.limit);