فهرست منبع

Revert nsfw posts hidden on local/network timelines by default

Daniel Supernault 2 سال پیش
والد
کامیت
5cac7fb44f

+ 14 - 4
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')

+ 2 - 2
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);
 		}

+ 4 - 1
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'])

+ 4 - 1
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')

+ 2 - 0
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),
 ];