forked from mirror/pixelfed
Update ApiControllers, use NotificationService
This commit is contained in:
parent
bce8edd994
commit
f9516ac316
2 changed files with 39 additions and 20 deletions
|
@ -1316,6 +1316,11 @@ class ApiV1Controller extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
if(empty($res) && !Cache::has('pf:services:notifications:hasSynced:'.$pid)) {
|
||||
Cache::put('pf:services:notifications:hasSynced:'.$pid, 1, 1209600);
|
||||
NotificationService::warmCache($pid, 400, true);
|
||||
}
|
||||
|
||||
$baseUrl = config('app.url') . '/api/v1/notifications?';
|
||||
|
||||
if($minId == $maxId) {
|
||||
|
|
|
@ -54,26 +54,40 @@ class BaseApiController extends Controller
|
|||
public function notifications(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 403);
|
||||
$pid = $request->user()->profile_id;
|
||||
$pg = $request->input('pg');
|
||||
if($pg == true) {
|
||||
$timeago = Carbon::now()->subMonths(6);
|
||||
$notifications = Notification::whereProfileId($pid)
|
||||
->whereDate('created_at', '>', $timeago)
|
||||
->latest()
|
||||
->simplePaginate(10);
|
||||
$resource = new Fractal\Resource\Collection($notifications, new NotificationTransformer());
|
||||
$res = $this->fractal->createData($resource)->toArray();
|
||||
} else {
|
||||
$this->validate($request, [
|
||||
'page' => 'nullable|integer|min:1|max:10',
|
||||
'limit' => 'nullable|integer|min:1|max:40'
|
||||
]);
|
||||
$limit = $request->input('limit') ?? 10;
|
||||
$page = $request->input('page') ?? 1;
|
||||
$end = (int) $page * $limit;
|
||||
$start = (int) $end - $limit;
|
||||
$res = NotificationService::get($pid, $start, $end);
|
||||
|
||||
$pid = $request->user()->profile_id;
|
||||
$limit = $request->input('limit', 20);
|
||||
|
||||
$since = $request->input('since_id');
|
||||
$min = $request->input('min_id');
|
||||
$max = $request->input('max_id');
|
||||
|
||||
if(!$since && !$min && !$max) {
|
||||
$min = 1;
|
||||
}
|
||||
|
||||
$maxId = null;
|
||||
$minId = null;
|
||||
|
||||
if($max) {
|
||||
$res = NotificationService::getMax($pid, $max, $limit);
|
||||
$ids = NotificationService::getRankedMaxId($pid, $max, $limit);
|
||||
if(!empty($ids)) {
|
||||
$maxId = max($ids);
|
||||
$minId = min($ids);
|
||||
}
|
||||
} else {
|
||||
$res = NotificationService::getMin($pid, $min ?? $since, $limit);
|
||||
$ids = NotificationService::getRankedMinId($pid, $min ?? $since, $limit);
|
||||
if(!empty($ids)) {
|
||||
$maxId = max($ids);
|
||||
$minId = min($ids);
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($res) && !Cache::has('pf:services:notifications:hasSynced:'.$pid)) {
|
||||
Cache::put('pf:services:notifications:hasSynced:'.$pid, 1, 1209600);
|
||||
NotificationService::warmCache($pid, 400, true);
|
||||
}
|
||||
|
||||
return response()->json($res);
|
||||
|
|
Loading…
Reference in a new issue