From 21947835f8969a6100d275897bc84f337b958994 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 21 Dec 2023 00:46:24 -0700 Subject: [PATCH] Update ApiV1Controller, use domainBlock filtering on public/network feeds --- app/Http/Controllers/Api/ApiV1Controller.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index e429a8681..be77b5606 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -31,6 +31,7 @@ use App\{ UserSetting, UserFilter, }; +use App\Models\UserDomainBlock; use League\Fractal; use App\Transformer\Api\Mastodon\v1\{ AccountTransformer, @@ -2422,6 +2423,7 @@ class ApiV1Controller extends Controller $local = $request->has('local'); $filtered = $user ? UserFilterService::filters($user->profile_id) : []; AccountService::setLastActive($user->id); + $domainBlocks = UserFilterService::domainBlocks($user->profile_id); if($remote && config('instance.timeline.network.cached')) { Cache::remember('api:v1:timelines:network:cache_check', 10368000, function() { @@ -2496,6 +2498,13 @@ class ApiV1Controller extends Controller ->filter(function($s) use($filtered) { return $s && isset($s['account']) && in_array($s['account']['id'], $filtered) == false; }) + ->filter(function($s) use($domainBlocks) { + if(!$domainBlocks || !count($domainBlocks)) { + return $s; + } + $domain = strtolower(parse_url($s['url'], PHP_URL_HOST)); + return !in_array($domain, $domainBlocks); + }) ->take($limit) ->values();