From 5cac7fb44f55b96e25c74d04da93c8e5bd1ea5fb Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 28 Nov 2022 05:13:12 -0700 Subject: [PATCH] Revert nsfw posts hidden on local/network timelines by default --- app/Http/Controllers/PublicApiController.php | 18 ++++++++++++++---- app/Jobs/StatusPipeline/StatusEntityLexer.php | 4 ++-- app/Services/NetworkTimelineService.php | 5 ++++- app/Services/PublicTimelineService.php | 5 ++++- config/instance.php | 2 ++ 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/PublicApiController.php b/app/Http/Controllers/PublicApiController.php index 98fb9d33e..3a406e955 100644 --- a/app/Http/Controllers/PublicApiController.php +++ b/app/Http/Controllers/PublicApiController.php @@ -307,6 +307,7 @@ class PublicApiController extends Controller $user = $request->user(); $filtered = $user ? UserFilterService::filters($user->profile_id) : []; + $hideNsfw = config('instance.hide_nsfw_on_public_feeds'); if(config('exp.cached_public_timeline') == false) { if($min || $max) { $dir = $min ? '>' : '<'; @@ -322,7 +323,9 @@ class PublicApiController extends Controller ->whereNull(['in_reply_to_id', 'reblog_of_id']) ->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album']) ->whereLocal(true) - ->where('is_nsfw', false) + ->when($hideNsfw, function($q, $hideNsfw) { + return $q->where('is_nsfw', false); + }) ->whereScope('public') ->orderBy('id', 'desc') ->limit($limit) @@ -366,7 +369,9 @@ class PublicApiController extends Controller ->whereNull(['in_reply_to_id', 'reblog_of_id']) ->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album']) ->whereLocal(true) - ->where('is_nsfw', false) + ->when($hideNsfw, function($q, $hideNsfw) { + return $q->where('is_nsfw', false); + }) ->whereScope('public') ->orderBy('id', 'desc') ->limit($limit) @@ -610,6 +615,7 @@ class PublicApiController extends Controller $amin = SnowflakeService::byDate(now()->subDays(config('federation.network_timeline_days_falloff'))); $filtered = $user ? UserFilterService::filters($user->profile_id) : []; + $hideNsfw = config('instance.hide_nsfw_on_public_feeds'); if(config('instance.timeline.network.cached') == false) { if($min || $max) { @@ -623,7 +629,9 @@ class PublicApiController extends Controller 'created_at', ) ->where('id', $dir, $id) - ->where('is_nsfw', false) + ->when($hideNsfw, function($q, $hideNsfw) { + return $q->where('is_nsfw', false); + }) ->whereNull(['in_reply_to_id', 'reblog_of_id']) ->whereNotIn('profile_id', $filtered) ->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album']) @@ -651,7 +659,9 @@ class PublicApiController extends Controller ) ->whereNull(['in_reply_to_id', 'reblog_of_id']) ->whereNotIn('profile_id', $filtered) - ->where('is_nsfw', false) + ->when($hideNsfw, function($q, $hideNsfw) { + return $q->where('is_nsfw', false); + }) ->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album']) ->whereNotNull('uri') ->whereScope('public') diff --git a/app/Jobs/StatusPipeline/StatusEntityLexer.php b/app/Jobs/StatusPipeline/StatusEntityLexer.php index 9732226c4..591a06604 100644 --- a/app/Jobs/StatusPipeline/StatusEntityLexer.php +++ b/app/Jobs/StatusPipeline/StatusEntityLexer.php @@ -166,13 +166,13 @@ class StatusEntityLexer implements ShouldQueue if(config_cache('pixelfed.bouncer.enabled')) { Bouncer::get($status); } - + $hideNsfw = config('instance.hide_nsfw_on_public_feeds'); if( $status->uri == null && $status->scope == 'public' && in_array($status->type, $types) && $status->in_reply_to_id === null && $status->reblog_of_id === null && - $status->is_nsfw == false + ($hideNsfw ? $status->is_nsfw == false : true) ) { PublicTimelineService::add($status->id); } diff --git a/app/Services/NetworkTimelineService.php b/app/Services/NetworkTimelineService.php index 3a5397784..a25f6712c 100644 --- a/app/Services/NetworkTimelineService.php +++ b/app/Services/NetworkTimelineService.php @@ -75,10 +75,13 @@ class NetworkTimelineService public static function warmCache($force = false, $limit = 100) { if(self::count() == 0 || $force == true) { + $hideNsfw = config('instance.hide_nsfw_on_public_feeds'); Redis::del(self::CACHE_KEY); $ids = Status::whereNotNull('uri') ->whereScope('public') - ->where('is_nsfw', false) + ->when($hideNsfw, function($q, $hideNsfw) { + return $q->where('is_nsfw', false); + }) ->whereNull('in_reply_to_id') ->whereNull('reblog_of_id') ->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album']) diff --git a/app/Services/PublicTimelineService.php b/app/Services/PublicTimelineService.php index 4e95842e4..75317aa80 100644 --- a/app/Services/PublicTimelineService.php +++ b/app/Services/PublicTimelineService.php @@ -75,10 +75,13 @@ class PublicTimelineService { public static function warmCache($force = false, $limit = 100) { if(self::count() == 0 || $force == true) { + $hideNsfw = config('instance.hide_nsfw_on_public_feeds'); Redis::del(self::CACHE_KEY); $ids = Status::whereNull('uri') ->whereNull('in_reply_to_id') - ->where('is_nsfw', false) + ->when($hideNsfw, function($q, $hideNsfw) { + return $q->where('is_nsfw', false); + }) ->whereNull('reblog_of_id') ->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album']) ->whereScope('public') diff --git a/config/instance.php b/config/instance.php index 9a7c48e32..528fe47b5 100644 --- a/config/instance.php +++ b/config/instance.php @@ -91,4 +91,6 @@ return [ 'profile' => env('INSTANCE_PROFILE_EMBEDS', true), 'post' => env('INSTANCE_POST_EMBEDS', true), ], + + 'hide_nsfw_on_public_feeds' => env('PF_HIDE_NSFW_ON_PUBLIC_FEEDS', false), ];