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

This commit is contained in:
Daniel Supernault 2019-09-25 23:36:13 -06:00
parent 3e98dce4de
commit 41c96ddd6a
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 39 additions and 4 deletions

View file

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

View file

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