From c3e8a0e4391ae1cdacb38a02b86a5f63645ce93e Mon Sep 17 00:00:00 2001
From: Daniel Supernault <danielsupernault@gmail.com>
Date: Mon, 15 Aug 2022 21:45:30 -0600
Subject: [PATCH] Improve mute/block v1 api endpoints, fixes #3540

---
 app/Http/Controllers/Api/ApiV1Controller.php | 29 ++++++++++++--------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php
index 72f76f25d..68558a3c2 100644
--- a/app/Http/Controllers/Api/ApiV1Controller.php
+++ b/app/Http/Controllers/Api/ApiV1Controller.php
@@ -873,12 +873,15 @@ class ApiV1Controller extends Controller
 			->whereFilterableType('App\Profile')
 			->whereFilterType('block')
 			->simplePaginate($limit)
-			->pluck('filterable_id');
+			->pluck('filterable_id')
+			->map(function($id) {
+				return AccountService::get($id, true);
+			})
+			->filter(function($account) {
+				return $account && isset($account['id']);
+			});
 
-		$profiles = Profile::findOrFail($blocked);
-		$resource = new Fractal\Resource\Collection($profiles, new AccountTransformer());
-		$res = $this->fractal->createData($resource)->toArray();
-		return $this->json($res);
+		return $this->json($blocked);
 	}
 
 	/**
@@ -1725,19 +1728,21 @@ class ApiV1Controller extends Controller
 		]);
 
 		$user = $request->user();
-		$limit = $request->input('limit') ?? 40;
+		$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);
+			->pluck('filterable_id')
+			->map(function($id) {
+				return AccountService::get($id, true);
+			})
+			->filter(function($account) {
+				return $account && isset($account['id']);
+			});
 
-		$resource = new Fractal\Resource\Collection($accounts, new AccountTransformer());
-		$res = $this->fractal->createData($resource)->toArray();
-		return $this->json($res);
+		return $this->json($mutes);
 	}
 
 	/**
-- 
GitLab