1
0
Fork 0

Merge pull request #2071 from pixelfed/staging

Update ApiV1Controller
This commit is contained in:
daniel 2020-02-27 23:33:20 -07:00 committed by GitHub
commit 7776cca9e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 9 deletions

View File

@ -205,19 +205,32 @@ class ApiV1Controller extends Controller
public function accountFollowersById(Request $request, $id)
{
abort_if(!$request->user(), 403);
$user = $request->user();
$profile = Profile::whereNull('status')->findOrFail($id);
$limit = $request->input('limit') ?? 40;
if($profile->domain) {
$res = [];
} else {
$settings = $profile->user->settings;
if($settings->show_profile_followers == true) {
$limit = $request->input('limit') ?? 40;
if($profile->id == $user->profile_id) {
$followers = $profile->followers()->paginate($limit);
$resource = new Fractal\Resource\Collection($followers, new AccountTransformer());
$res = $this->fractal->createData($resource)->toArray();
} else {
$res = [];
if($profile->is_private) {
abort_if(!$profile->followedBy($user->profile), 403);
}
$settings = $profile->user->settings;
if( in_array($user->profile_id, $profile->blockedIds()->toArray()) ||
$settings->show_profile_followers == false
) {
$res = [];
} else {
$followers = $profile->followers()->paginate($limit);
$resource = new Fractal\Resource\Collection($followers, new AccountTransformer());
$res = $this->fractal->createData($resource)->toArray();
}
}
}
return response()->json($res);
@ -233,22 +246,36 @@ class ApiV1Controller extends Controller
public function accountFollowingById(Request $request, $id)
{
abort_if(!$request->user(), 403);
$user = $request->user();
$profile = Profile::whereNull('status')->findOrFail($id);
$limit = $request->input('limit') ?? 40;
if($profile->domain) {
$res = [];
} else {
$settings = $profile->user->settings;
if($settings->show_profile_following == true) {
$limit = $request->input('limit') ?? 40;
if($profile->id == $user->profile_id) {
$following = $profile->following()->paginate($limit);
$resource = new Fractal\Resource\Collection($following, new AccountTransformer());
$res = $this->fractal->createData($resource)->toArray();
} else {
$res = [];
if($profile->is_private) {
abort_if(!$profile->followedBy($user->profile), 403);
}
$settings = $profile->user->settings;
if( in_array($user->profile_id, $profile->blockedIds()->toArray()) ||
$settings->show_profile_following == false
) {
$res = [];
} else {
$following = $profile->following()->paginate($limit);
$resource = new Fractal\Resource\Collection($following, new AccountTransformer());
$res = $this->fractal->createData($resource)->toArray();
}
}
}
return response()->json($res);
}