From f61159a15a64e665b7fec1c062645b81fa22726f Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 2 Jul 2024 00:42:22 -0600 Subject: [PATCH 1/6] Update ApiV1Controller, add support for notification filter types[] --- app/Http/Controllers/Api/ApiV1Controller.php | 29 ++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index f6f6c6a39..36d1aa2d9 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -211,6 +211,7 @@ class ApiV1Controller extends Controller abort_if(! $request->user() || ! $request->user()->token(), 403); abort_unless($request->user()->tokenCan('read'), 403); + $withInstanceMeta = $request->has('_wim'); $res = $request->has(self::PF_API_ENTITY_KEY) ? AccountService::get($id, true) : AccountService::getMastodon($id, true); if (! $res) { return response()->json(['error' => 'Record not found'], 404); @@ -752,7 +753,15 @@ class ApiV1Controller extends Controller $dir = $min_id ? '>' : '<'; $id = $min_id ?? $max_id; - $res = Status::whereProfileId($profile['id']) + $res = Status::select( + 'profile_id', + 'in_reply_to_id', + 'reblog_of_id', + 'type', + 'id', + 'scope' + ) + ->whereProfileId($profile['id']) ->whereNull('in_reply_to_id') ->whereNull('reblog_of_id') ->whereIn('type', $scope) @@ -2272,14 +2281,17 @@ class ApiV1Controller extends Controller 'max_id' => 'nullable|integer|min:1|max:'.PHP_INT_MAX, 'since_id' => 'nullable|integer|min:1|max:'.PHP_INT_MAX, 'types[]' => 'sometimes|array', + 'types[].*' => 'string|in:mention,reblog,follow,favourite', 'type' => 'sometimes|string|in:mention,reblog,follow,favourite', '_pe' => 'sometimes', ]); $pid = $request->user()->profile_id; $limit = $request->input('limit', 20); + $ogLimit = $request->input('limit', 20); if ($limit > 40) { $limit = 40; + $ogLimit = 40; } $since = $request->input('since_id'); @@ -2297,6 +2309,10 @@ class ApiV1Controller extends Controller $types = $request->input('types'); + if ($request->has('types')) { + $limit = 150; + } + $maxId = null; $minId = null; AccountService::setLastActive($request->user()->id); @@ -2361,7 +2377,16 @@ class ApiV1Controller extends Controller } return true; - })->values(); + }) + ->filter(function ($n) use ($types) { + if (! $types) { + return true; + } + + return in_array($n['type'], $types); + }) + ->take($ogLimit) + ->values(); if ($maxId) { $link = '<'.$baseUrl.'max_id='.$minId.'>; rel="next"'; From 49461af3978da9c2eec10bb2afc5180f3f7d7741 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 2 Jul 2024 00:43:05 -0600 Subject: [PATCH 2/6] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index afba4ed33..437fe426b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Release Notes ## [Unreleased](https://github.com/pixelfed/pixelfed/compare/v0.12.3...dev) + +### Updates +- Update ApiV1Controller, add support for notification filter types ([f61159a1](https://github.com/pixelfed/pixelfed/commit/f61159a1)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.12.3 (2024-07-01)](https://github.com/pixelfed/pixelfed/compare/v0.12.2...v0.12.3) From 2b9586fce1c9434e4d816991d6d36281f521986a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 2 Jul 2024 00:46:22 -0600 Subject: [PATCH 3/6] Update ApiV1Controller.php --- app/Http/Controllers/Api/ApiV1Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 36d1aa2d9..fad23de55 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -2335,7 +2335,7 @@ class ApiV1Controller extends Controller } } - $baseUrl = config('app.url').'/api/v1/notifications?limit='.$limit.'&'; + $baseUrl = config('app.url').'/api/v1/notifications?limit='.$ogLimit.'&'; if ($minId == $maxId) { $minId = null; From f61bbecaa9d2568470ec23e870ccb148ce0ba0c4 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 2 Jul 2024 01:00:31 -0600 Subject: [PATCH 4/6] Update ApiV1Controller, fix support for notification filter types[] --- app/Http/Controllers/Api/ApiV1Controller.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index fad23de55..627a6d3e8 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -2335,7 +2335,12 @@ class ApiV1Controller extends Controller } } - $baseUrl = config('app.url').'/api/v1/notifications?limit='.$ogLimit.'&'; + if ($request->has('types')) { + $typesParams = collect($types)->implode('&types[]='); + $baseUrl = config('app.url').'/api/v1/notifications?types[]='.$typesParams.'&limit='.$ogLimit.'&'; + } else { + $baseUrl = config('app.url').'/api/v1/notifications?limit='.$ogLimit.'&'; + } if ($minId == $maxId) { $minId = null; From a8bb97b22b14374210f1d1feb304549899eaffa0 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 2 Jul 2024 04:00:27 -0600 Subject: [PATCH 5/6] Update ApiV1Dot1Controller, fix mutual api --- app/Http/Controllers/Api/ApiV1Dot1Controller.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Dot1Controller.php b/app/Http/Controllers/Api/ApiV1Dot1Controller.php index 7165629c2..9a47bb150 100644 --- a/app/Http/Controllers/Api/ApiV1Dot1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Dot1Controller.php @@ -487,8 +487,7 @@ class ApiV1Dot1Controller extends Controller abort_if(BouncerService::checkIp($request->ip()), 404); } - $rl = RateLimiter::attempt('pf:apiv1.1:iar:'.$request->ip(), config('pixelfed.app_registration_rate_limit_attempts', 3), function () { - }, config('pixelfed.app_registration_rate_limit_decay', 1800)); + $rl = RateLimiter::attempt('pf:apiv1.1:iar:'.$request->ip(), config('pixelfed.app_registration_rate_limit_attempts', 3), function () {}, config('pixelfed.app_registration_rate_limit_decay', 1800)); abort_if(! $rl, 400, 'Too many requests'); $this->validate($request, [ @@ -618,8 +617,7 @@ class ApiV1Dot1Controller extends Controller abort_if(BouncerService::checkIp($request->ip()), 404); } - $rl = RateLimiter::attempt('pf:apiv1.1:iarc:'.$request->ip(), config('pixelfed.app_registration_confirm_rate_limit_attempts', 20), function () { - }, config('pixelfed.app_registration_confirm_rate_limit_decay', 1800)); + $rl = RateLimiter::attempt('pf:apiv1.1:iarc:'.$request->ip(), config('pixelfed.app_registration_confirm_rate_limit_attempts', 20), function () {}, config('pixelfed.app_registration_confirm_rate_limit_decay', 1800)); abort_if(! $rl, 429, 'Too many requests'); $request->validate([ @@ -929,7 +927,7 @@ class ApiV1Dot1Controller extends Controller public function getMutualAccounts(Request $request, $id) { abort_if(! $request->user() || ! $request->user()->token(), 403); - abort_unless($request->user()->tokenCan('follows'), 403); + abort_unless($request->user()->tokenCan('follow'), 403); $account = AccountService::get($id, true); if (! $account || ! isset($account['id'])) { From 2aa8dd8613147568d13e875d8b4976f91eec675d Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 2 Jul 2024 04:01:13 -0600 Subject: [PATCH 6/6] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 437fe426b..96ec84051 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Updates - Update ApiV1Controller, add support for notification filter types ([f61159a1](https://github.com/pixelfed/pixelfed/commit/f61159a1)) +- Update ApiV1Dot1Controller, fix mutual api ([a8bb97b2](https://github.com/pixelfed/pixelfed/commit/a8bb97b2)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.12.3 (2024-07-01)](https://github.com/pixelfed/pixelfed/compare/v0.12.2...v0.12.3)