From 3e98dce4de06fe24645b9bc9ef103874557f4266 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 25 Sep 2019 23:31:19 -0600 Subject: [PATCH] Add /api/v1/accounts/{id}/mute endpoint --- app/Http/Controllers/Api/ApiV1Controller.php | 32 ++++++++++++++++++++ routes/web.php | 3 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index bbb58ac2e..415cebed7 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -1025,6 +1025,38 @@ class ApiV1Controller extends Controller return response()->json($res); } + /** + * POST /api/v1/accounts/{id}/mute + * + * @param integer $id + * + * @return App\Transformer\Api\AccountTransformer + */ + public function accountMuteById(Request $request, $id) + { + abort_if(!$request->user(), 403); + + $user = $request->user(); + + $account = Profile::findOrFail($id); + + $filter = UserFilter::firstOrCreate([ + 'user_id' => $user->profile_id, + 'filterable_id' => $account->id, + 'filterable_type' => 'App\Profile', + 'filter_type' => 'mute', + ]); + + $pid = $user->profile_id; + Cache::forget("user:filter:list:$pid"); + Cache::forget("feature:discover:posts:$pid"); + Cache::forget("api:local:exp:rec:$pid"); + + $resource = new Fractal\Resource\Item($account, new RelationshipTransformer()); + $res = $this->fractal->createData($resource)->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 58592fc34..127cf9a34 100644 --- a/routes/web.php +++ b/routes/web.php @@ -113,7 +113,8 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::post('media', 'Api\ApiV1Controller@mediaUpload')->middleware('auth:api'); Route::put('media/{id}', 'Api\ApiV1Controller@mediaUpdate')->middleware('auth:api'); Route::get('mutes', 'Api\ApiV1Controller@accountMutes')->middleware('auth:api'); - + Route::post('accounts/{id}/mute', 'Api\ApiV1Controller@accountMuteById')->middleware('auth:api'); + // Route::get('likes', 'ApiController@hydrateLikes'); // Route::post('media', 'ApiController@uploadMedia')->middleware('auth:api'); // Route::delete('media', 'ApiController@deleteMedia')->middleware('auth:api');