diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 916474f0..9d579951 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -442,6 +442,32 @@ class ApiV1Controller extends Controller return response()->json($res); } + /** + * GET /api/v1/accounts/relationships + * + * @param array|integer $id + * + * @return \App\Transformer\Api\RelationshipTransformer + */ + public function accountRelationshipsById(Request $request) + { + abort_if(!$request->user(), 403); + + $this->validate($request, [ + 'id' => 'required|array|min:1|max:20', + 'id.*' => 'required|integer|min:1|max:' . PHP_INT_MAX + ]); + $pid = $request->user()->profile_id ?? $request->user()->profile->id; + $ids = collect($request->input('id')); + $filtered = $ids->filter(function($v) use($pid) { + return $v != $pid; + }); + $relations = Profile::whereNull('status')->findOrFail($filtered->values()); + $fractal = new Fractal\Resource\Collection($relations, new RelationshipTransformer()); + $res = $this->fractal->createData($fractal)->toArray(); + return response()->json($res); + } + public function statusById(Request $request, $id) { $status = Status::whereVisibility('public')->findOrFail($id); diff --git a/routes/web.php b/routes/web.php index c225f170..c56f29d9 100644 --- a/routes/web.php +++ b/routes/web.php @@ -79,7 +79,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::group(['prefix' => 'v1'], function () { Route::get('accounts/verify_credentials', 'ApiController@verifyCredentials')->middleware('auth:api'); Route::patch('accounts/update_credentials', 'Api\ApiV1Controller@accountUpdateCredentials')->middleware('auth:api'); - Route::get('accounts/relationships', 'PublicApiController@relationships')->middleware('auth:api'); + Route::get('accounts/relationships', 'Api\ApiV1Controller@accountRelationshipsById')->middleware('auth:api'); Route::get('accounts/{id}/statuses', 'Api\ApiV1Controller@accountStatusesById')->middleware('auth:api'); Route::get('accounts/{id}/following', 'Api\ApiV1Controller@accountFollowingById')->middleware('auth:api'); Route::get('accounts/{id}/followers', 'Api\ApiV1Controller@accountFollowersById')->middleware('auth:api'); @@ -115,7 +115,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::group(['prefix' => 'pixelfed'], function() { Route::group(['prefix' => 'v1'], function() { Route::get('accounts/verify_credentials', 'ApiController@verifyCredentials'); - Route::get('accounts/relationships', 'PublicApiController@relationships'); + Route::get('accounts/relationships', 'Api\ApiV1Controller@accountRelationshipsById'); Route::get('accounts/{id}/statuses', 'PublicApiController@accountStatuses'); Route::get('accounts/{id}/following', 'PublicApiController@accountFollowing'); Route::get('accounts/{id}/followers', 'PublicApiController@accountFollowers');