From 41c96ddd6ada638e79a1e82bc40342f0e27e2d9f Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 25 Sep 2019 23:36:13 -0600 Subject: [PATCH] Add /api/v1/accounts/{id}/unmute endpoint --- app/Http/Controllers/Api/ApiV1Controller.php | 40 ++++++++++++++++++-- routes/web.php | 3 +- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 415cebed..4d501595 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -1030,24 +1030,24 @@ class ApiV1Controller extends Controller * * @param integer $id * - * @return App\Transformer\Api\AccountTransformer + * @return App\Transformer\Api\RelationshipTransformer */ public function accountMuteById(Request $request, $id) { abort_if(!$request->user(), 403); $user = $request->user(); + $pid = $user->profile_id; $account = Profile::findOrFail($id); $filter = UserFilter::firstOrCreate([ - 'user_id' => $user->profile_id, + 'user_id' => $pid, '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"); @@ -1057,6 +1057,40 @@ class ApiV1Controller extends Controller return response()->json($res); } + /** + * POST /api/v1/accounts/{id}/unmute + * + * @param integer $id + * + * @return App\Transformer\Api\RelationshipTransformer + */ + public function accountUnmuteById(Request $request, $id) + { + abort_if(!$request->user(), 403); + + $user = $request->user(); + $pid = $user->profile_id; + + $account = Profile::findOrFail($id); + + $filter = UserFilter::whereUserId($pid) + ->whereFilterableId($account->id) + ->whereFilterableType('App\Profile') + ->whereFilterType('mute') + ->first(); + + if($filter) { + $filter->delete(); + 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 127cf9a3..d295d360 100644 --- a/routes/web.php +++ b/routes/web.php @@ -91,7 +91,6 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::post('accounts/{id}/pin', 'Api\ApiV1Controller@accountEndorsements')->middleware('auth:api'); Route::post('accounts/{id}/unpin', 'Api\ApiV1Controller@accountEndorsements')->middleware('auth:api'); // Route::get('accounts/{id}', 'PublicApiController@account'); - Route::get('accounts/{id}', 'Api\ApiV1Controller@accountById'); Route::post('avatar/update', 'ApiController@avatarUpdate')->middleware('auth:api'); Route::get('domain_blocks', 'Api\ApiV1Controller@accountDomainBlocks')->middleware('auth:api'); Route::post('domain_blocks', 'Api\ApiV1Controller@accountDomainBlocks')->middleware('auth:api'); @@ -114,6 +113,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact 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::post('accounts/{id}/unmute', 'Api\ApiV1Controller@accountUnmuteById')->middleware('auth:api'); // Route::get('likes', 'ApiController@hydrateLikes'); // Route::post('media', 'ApiController@uploadMedia')->middleware('auth:api'); @@ -122,6 +122,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact // Route::get('timelines/public', 'PublicApiController@publicTimelineApi'); // Route::get('timelines/home', 'PublicApiController@homeTimelineApi')->middleware('auth:api'); // Route::post('status', 'Api\ApiV1Controller@createStatus')->middleware('auth:api'); + Route::get('accounts/{id}', 'Api\ApiV1Controller@accountById'); }); Route::group(['prefix' => 'v2'], function() { Route::get('config', 'ApiController@siteConfiguration');