From 1fb7e2b2c97b3a15b17bd4ccabc7d6ec71451212 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 31 Jan 2021 13:45:22 -0700 Subject: [PATCH 1/2] Update AccountController, add mutes and blocks endpoint to pixelfed api --- app/Http/Controllers/AccountController.php | 66 ++++++++++++++++++++++ routes/web.php | 2 + 2 files changed, 68 insertions(+) diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index d0c3d4563..85ee74281 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -22,6 +22,10 @@ use App\{ User, UserFilter }; +use League\Fractal; +use League\Fractal\Serializer\ArraySerializer; +use League\Fractal\Pagination\IlluminatePaginatorAdapter; +use App\Transformer\Api\Mastodon\v1\AccountTransformer; class AccountController extends Controller { @@ -487,4 +491,66 @@ class AccountController extends Controller public function accountRestored(Request $request) { } + + public function accountMutes(Request $request) + { + abort_if(!$request->user(), 403); + + $this->validate($request, [ + 'limit' => 'nullable|integer|min:1|max:40' + ]); + + $user = $request->user(); + $limit = $request->input('limit') ?? 40; + + $mutes = UserFilter::whereUserId($user->profile_id) + ->whereFilterableType('App\Profile') + ->whereFilterType('mute') + ->simplePaginate($limit) + ->pluck('filterable_id'); + + $accounts = Profile::find($mutes); + $fractal = new Fractal\Manager(); + $fractal->setSerializer(new ArraySerializer()); + $resource = new Fractal\Resource\Collection($accounts, new AccountTransformer()); + $res = $fractal->createData($resource)->toArray(); + $url = $request->url(); + $page = $request->input('page', 1); + $next = $page < 40 ? $page + 1 : 40; + $prev = $page > 1 ? $page - 1 : 1; + $links = '<'.$url.'?page='.$next.'&limit='.$limit.'>; rel="next", <'.$url.'?page='.$prev.'&limit='.$limit.'>; rel="prev"'; + return response()->json($res, 200, ['Link' => $links]); + } + + public function accountBlocks(Request $request) + { + abort_if(!$request->user(), 403); + + $this->validate($request, [ + 'limit' => 'nullable|integer|min:1|max:40', + 'page' => 'nullable|integer|min:1|max:10' + ]); + + $user = $request->user(); + $limit = $request->input('limit') ?? 40; + + $blocked = UserFilter::select('filterable_id','filterable_type','filter_type','user_id') + ->whereUserId($user->profile_id) + ->whereFilterableType('App\Profile') + ->whereFilterType('block') + ->simplePaginate($limit) + ->pluck('filterable_id'); + + $profiles = Profile::findOrFail($blocked); + $fractal = new Fractal\Manager(); + $fractal->setSerializer(new ArraySerializer()); + $resource = new Fractal\Resource\Collection($profiles, new AccountTransformer()); + $res = $fractal->createData($resource)->toArray(); + $url = $request->url(); + $page = $request->input('page', 1); + $next = $page < 40 ? $page + 1 : 40; + $prev = $page > 1 ? $page - 1 : 1; + $links = '<'.$url.'?page='.$next.'&limit='.$limit.'>; rel="next", <'.$url.'?page='.$prev.'&limit='.$limit.'>; rel="prev"'; + return response()->json($res, 200, ['Link' => $links]); + } } diff --git a/routes/web.php b/routes/web.php index fb51d6f36..1a40f506d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -172,6 +172,8 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::get('newsroom/timeline', 'NewsroomController@timelineApi'); Route::post('newsroom/markasread', 'NewsroomController@markAsRead'); Route::get('favourites', 'Api\BaseApiController@accountLikes'); + Route::get('mutes', 'AccountController@accountMutes'); + Route::get('blocks', 'AccountController@accountBlocks'); }); Route::group(['prefix' => 'v2'], function() { From 61c71e8905bd2ac8208b6d92def679ed5ca29469 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 31 Jan 2021 13:45:58 -0700 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5090a8383..3635338ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Updated InternalApiController, update discoverPosts method to improve performance. ([9862a855](https://github.com/pixelfed/pixelfed/commit/9862a855)) - Updated DiscoverComponent, add blurhash and like/comment counts. ([a8ebdd2e](https://github.com/pixelfed/pixelfed/commit/a8ebdd2e)) - Updated DiscoverComponent, add spinner loaders and remove deprecated sections. ([34869247](https://github.com/pixelfed/pixelfed/commit/34869247)) +- Updated AccountController, add mutes and blocks endpoint to pixelfed api. ([1fb7e2b2](https://github.com/pixelfed/pixelfed/commit/1fb7e2b2)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.10.10 (2021-01-28)](https://github.com/pixelfed/pixelfed/compare/v0.10.9...v0.10.10)