Add /api/v1/accounts/{id}/mute endpoint

This commit is contained in:
Daniel Supernault 2019-09-25 23:31:19 -06:00
parent b280d183ad
commit 3e98dce4de
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 34 additions and 1 deletions

View file

@ -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);

View file

@ -113,6 +113,7 @@ 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');