mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-10 00:34:50 +00:00
Update ApiV1Controller
This commit is contained in:
parent
fb91892ee2
commit
bd45728615
1 changed files with 30 additions and 21 deletions
|
@ -1164,34 +1164,43 @@ class ApiV1Controller extends Controller
|
||||||
public function accountNotifications(Request $request)
|
public function accountNotifications(Request $request)
|
||||||
{
|
{
|
||||||
abort_if(!$request->user(), 403);
|
abort_if(!$request->user(), 403);
|
||||||
|
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'page' => 'nullable|integer|min:1|max:10',
|
|
||||||
'limit' => 'nullable|integer|min:1|max:80',
|
'limit' => 'nullable|integer|min:1|max:80',
|
||||||
'max_id' => 'nullable|integer|min:1',
|
'min_id' => 'nullable|integer|min:1|max:'.PHP_INT_MAX,
|
||||||
'min_id' => 'nullable|integer|min:0',
|
'max_id' => 'nullable|integer|min:1|max:'.PHP_INT_MAX,
|
||||||
|
'since_id' => 'nullable|integer|min:1|max:'.PHP_INT_MAX,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$pid = $request->user()->profile_id;
|
$pid = $request->user()->profile_id;
|
||||||
$limit = $request->input('limit') ?? 20;
|
$limit = $request->input('limit', 20);
|
||||||
$timeago = now()->subMonths(6);
|
$timeago = now()->subMonths(6);
|
||||||
|
|
||||||
|
$since = $request->input('since_id');
|
||||||
$min = $request->input('min_id');
|
$min = $request->input('min_id');
|
||||||
$max = $request->input('max_id');
|
$max = $request->input('max_id');
|
||||||
if($min || $max) {
|
|
||||||
$dir = $min ? '>' : '<';
|
abort_if(!$since && !$min && !$max, 400);
|
||||||
$id = $min ?? $max;
|
|
||||||
$notifications = Notification::whereProfileId($pid)
|
$dir = $since ? '>' : ($min ? '>=' : '<');
|
||||||
->whereDate('created_at', '>', $timeago)
|
$id = $since ?? $min ?? $max;
|
||||||
->where('id', $dir, $id)
|
|
||||||
->orderByDesc('created_at')
|
$notifications = Notification::whereProfileId($pid)
|
||||||
->limit($limit)
|
->where('id', $dir, $id)
|
||||||
->get();
|
->whereDate('created_at', '>', $timeago)
|
||||||
} else {
|
->orderByDesc('id')
|
||||||
$notifications = Notification::whereProfileId($pid)
|
->limit($limit)
|
||||||
->whereDate('created_at', '>', $timeago)
|
->get();
|
||||||
->orderByDesc('created_at')
|
|
||||||
->simplePaginate($limit);
|
$resource = new Fractal\Resource\Collection(
|
||||||
}
|
$notifications,
|
||||||
$resource = new Fractal\Resource\Collection($notifications, new NotificationTransformer());
|
new NotificationTransformer()
|
||||||
$res = $this->fractal->createData($resource)->toArray();
|
);
|
||||||
|
|
||||||
|
$res = $this->fractal
|
||||||
|
->createData($resource)
|
||||||
|
->toArray();
|
||||||
|
|
||||||
return response()->json($res);
|
return response()->json($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue