Update SearchApiV2Service, fix offset bug. Fixes #5875

pull/5925/head
Daniel Supernault 5 months ago
parent 4732019087
commit 0a98b7ad20
No known key found for this signature in database
GPG Key ID: 23740873EE6F76A1

@ -132,7 +132,6 @@ class SearchApiV2Service
$q = $this->query->input('q');
$limit = $this->query->input('limit') ?? 20;
$offset = $this->query->input('offset') ?? 0;
$query = Str::startsWith($q, '#') ? substr($q, 1) : $q;
$query = $query.'%';
@ -214,6 +213,9 @@ class SearchApiV2Service
$user = request()->user();
$mastodonMode = self::$mastodonMode;
$query = urldecode($this->query->input('q'));
$limit = $this->query->input('limit') ?? 20;
$offset = $this->query->input('offset') ?? 0;
$banned = InstanceService::getBannedDomains();
$domainBlocks = UserFilterService::domainBlocks($user->profile_id);
if ($domainBlocks && count($domainBlocks)) {
@ -252,7 +254,12 @@ class SearchApiV2Service
if (in_array($domain, $banned)) {
return $default;
}
$default['accounts'][] = $res;
$paginated = collect($res)->take($limit)->skip($offset)->toArray();
if (! empty($paginated)) {
$default['accounts'][] = $paginated;
} else {
$default['accounts'] = [];
}
return $default;
} else {
@ -271,7 +278,12 @@ class SearchApiV2Service
if (in_array($domain, $banned)) {
return $default;
}
$default['accounts'][] = $res;
$paginated = collect($res)->take($limit)->skip($offset)->toArray();
if (! empty($paginated)) {
$default['accounts'][] = $paginated;
} else {
$default['accounts'] = [];
}
return $default;
} else {

Loading…
Cancel
Save