Update CustomFilter model and CustomFilterController

pull/5928/head
Daniel Supernault 5 months ago
parent 168816db2d
commit b86102823b
No known key found for this signature in database
GPG Key ID: 23740873EE6F76A1

@ -2559,21 +2559,23 @@ class ApiV1Controller extends Controller
->filter(function ($s) use ($includeReblogs) {
return $includeReblogs ? true : $s['reblog'] == null;
})
->filter(function ($s) use ($homeFilters) {
$filterResults = CustomFilter::applyCachedFilters($homeFilters, $s);
->map(function($status) use ($homeFilters) {
$filterResults = CustomFilter::applyCachedFilters($homeFilters, $status);
if (! empty($filterResults)) {
$shouldHide = collect($filterResults)->contains(function ($result) {
return $result['filter']->action === CustomFilter::ACTION_HIDE;
if (!empty($filterResults)) {
$status['filtered'] = $filterResults;
$shouldHide = collect($filterResults)->contains(function($result) {
return $result['filter']['filter_action'] === "hide";
});
if ($shouldHide) {
return false;
return null;
}
}
return true;
return $status;
})
->filter()
->take($limit)
->map(function ($status) use ($pid) {
if ($pid) {
@ -2682,6 +2684,23 @@ class ApiV1Controller extends Controller
return $status;
})
->map(function($status) use ($homeFilters) {
$filterResults = CustomFilter::applyCachedFilters($homeFilters, $status);
if (!empty($filterResults)) {
$status['filtered'] = $filterResults;
$shouldHide = collect($filterResults)->contains(function($result) {
return $result['filter']['filter_action'] === "hide";
});
if ($shouldHide) {
return null;
}
}
return $status;
})
->filter()
->take($limit)
->values();
} else {
@ -2736,6 +2755,23 @@ class ApiV1Controller extends Controller
return $status;
})
->map(function($status) use ($homeFilters) {
$filterResults = CustomFilter::applyCachedFilters($homeFilters, $status);
if (!empty($filterResults)) {
$status['filtered'] = $filterResults;
$shouldHide = collect($filterResults)->contains(function($result) {
return $result['filter']['filter_action'] === "hide";
});
if ($shouldHide) {
return null;
}
}
return $status;
})
->filter()
->take($limit)
->values();
}
@ -2797,7 +2833,7 @@ class ApiV1Controller extends Controller
$limit = 40;
}
$user = $request->user();
$pid = $user->profile_id;
$remote = $request->has('remote') && $request->boolean('remote');
$local = $request->boolean('local');
$userRoleKey = $remote ? 'can-view-network-feed' : 'can-view-public-feed';
@ -2810,6 +2846,14 @@ class ApiV1Controller extends Controller
$hideNsfw = config('instance.hide_nsfw_on_public_feeds');
$amin = SnowflakeService::byDate(now()->subDays(config('federation.network_timeline_days_falloff')));
$asf = AdminShadowFilterService::getHideFromPublicFeedsList();
$cachedFilters = CustomFilter::getCachedFiltersForAccount($pid);
$homeFilters = array_filter($cachedFilters, function ($item) {
[$filter, $rules] = $item;
return in_array('public', $filter->context);
});
if ($local && $remote) {
$feed = Status::select(
'id',
@ -3000,6 +3044,23 @@ class ApiV1Controller extends Controller
return true;
})
->map(function($status) use ($homeFilters) {
$filterResults = CustomFilter::applyCachedFilters($homeFilters, $status);
if (!empty($filterResults)) {
$status['filtered'] = $filterResults;
$shouldHide = collect($filterResults)->contains(function($result) {
return $result['filter']['filter_action'] === "hide";
});
if ($shouldHide) {
return null;
}
}
return $status;
})
->filter()
->take($limit)
->values();

@ -281,7 +281,7 @@ class CustomFilterController extends Controller
]);
$rateKey = 'filters_updated:'.$request->user()->id;
$maxUpdatesPerHour = 30;
$maxUpdatesPerHour = CustomFilter::MAX_UPDATES_PER_HOUR;
$currentCount = Cache::get($rateKey, 0);
if ($currentCount >= $maxUpdatesPerHour) {

@ -43,6 +43,8 @@ class CustomFilter extends Model
const MAX_PER_HOUR = 40;
const MAX_UPDATES_PER_HOUR = 40;
const EXPIRATION_DURATIONS = [
1800, // 30 minutes
3600, // 1 hour

Loading…
Cancel
Save