Update ApiV1Controller, use domainBlock filtering on public/network feeds

This commit is contained in:
Daniel Supernault 2023-12-21 00:46:24 -07:00
parent 6d81214138
commit 21947835f8
No known key found for this signature in database
GPG Key ID: 23740873EE6F76A1
1 changed files with 9 additions and 0 deletions

View File

@ -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();