mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-25 07:45:22 +00:00
Add /api/v1/notifications endpoint
This commit is contained in:
parent
9b130cfe9b
commit
39449f3638
2 changed files with 46 additions and 2 deletions
|
@ -19,12 +19,15 @@ use App\{
|
||||||
UserFilter,
|
UserFilter,
|
||||||
};
|
};
|
||||||
use League\Fractal;
|
use League\Fractal;
|
||||||
use App\Transformer\Api\{
|
use App\Transformer\Api\Mastodon\v1\{
|
||||||
AccountTransformer,
|
AccountTransformer,
|
||||||
MediaTransformer,
|
MediaTransformer,
|
||||||
RelationshipTransformer,
|
NotificationTransformer,
|
||||||
StatusTransformer,
|
StatusTransformer,
|
||||||
};
|
};
|
||||||
|
use App\Transformer\Api\{
|
||||||
|
RelationshipTransformer,
|
||||||
|
};
|
||||||
use App\Http\Controllers\FollowerController;
|
use App\Http\Controllers\FollowerController;
|
||||||
use League\Fractal\Serializer\ArraySerializer;
|
use League\Fractal\Serializer\ArraySerializer;
|
||||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||||
|
@ -1091,6 +1094,46 @@ class ApiV1Controller extends Controller
|
||||||
return response()->json($res);
|
return response()->json($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/v1/notifications
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return App\Transformer\Api\NotificationTransformer
|
||||||
|
*/
|
||||||
|
public function accountNotifications(Request $request)
|
||||||
|
{
|
||||||
|
abort_if(!$request->user(), 403);
|
||||||
|
$this->validate($request, [
|
||||||
|
'page' => 'nullable|integer|min:1|max:10',
|
||||||
|
'limit' => 'nullable|integer|min:1|max:40',
|
||||||
|
'max_id' => 'nullable|integer|min:1',
|
||||||
|
'min_id' => 'nullable|integer|min:0',
|
||||||
|
]);
|
||||||
|
$pid = $request->user()->profile_id;
|
||||||
|
$limit = $request->input('limit') ?? 20;
|
||||||
|
$timeago = now()->subMonths(6);
|
||||||
|
$min = $request->input('min_id');
|
||||||
|
$max = $request->input('max_id');
|
||||||
|
if($min || $max) {
|
||||||
|
$dir = $min ? '>' : '<';
|
||||||
|
$id = $min ?? $max;
|
||||||
|
$notifications = Notification::whereProfileId($pid)
|
||||||
|
->whereDate('created_at', '>', $timeago)
|
||||||
|
->latest()
|
||||||
|
->where('id', $dir, $id)
|
||||||
|
->limit($limit)
|
||||||
|
->get();
|
||||||
|
} else {
|
||||||
|
$notifications = Notification::whereProfileId($pid)
|
||||||
|
->whereDate('created_at', '>', $timeago)
|
||||||
|
->latest()
|
||||||
|
->simplePaginate($limit);
|
||||||
|
}
|
||||||
|
$resource = new Fractal\Resource\Collection($notifications, new NotificationTransformer());
|
||||||
|
$res = $this->fractal->createData($resource)->toArray();
|
||||||
|
return response()->json($res);
|
||||||
|
}
|
||||||
|
|
||||||
public function statusById(Request $request, $id)
|
public function statusById(Request $request, $id)
|
||||||
{
|
{
|
||||||
$status = Status::whereVisibility('public')->findOrFail($id);
|
$status = Status::whereVisibility('public')->findOrFail($id);
|
||||||
|
|
|
@ -114,6 +114,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
|
||||||
Route::get('mutes', 'Api\ApiV1Controller@accountMutes')->middleware('auth:api');
|
Route::get('mutes', 'Api\ApiV1Controller@accountMutes')->middleware('auth:api');
|
||||||
Route::post('accounts/{id}/mute', 'Api\ApiV1Controller@accountMuteById')->middleware('auth:api');
|
Route::post('accounts/{id}/mute', 'Api\ApiV1Controller@accountMuteById')->middleware('auth:api');
|
||||||
Route::post('accounts/{id}/unmute', 'Api\ApiV1Controller@accountUnmuteById')->middleware('auth:api');
|
Route::post('accounts/{id}/unmute', 'Api\ApiV1Controller@accountUnmuteById')->middleware('auth:api');
|
||||||
|
Route::get('notifications', 'Api\ApiV1Controller@accountNotifications')->middleware('auth:api');
|
||||||
|
|
||||||
// Route::get('likes', 'ApiController@hydrateLikes');
|
// Route::get('likes', 'ApiController@hydrateLikes');
|
||||||
// Route::post('media', 'ApiController@uploadMedia')->middleware('auth:api');
|
// Route::post('media', 'ApiController@uploadMedia')->middleware('auth:api');
|
||||||
|
|
Loading…
Reference in a new issue