Skip to content

Commit

Permalink
Merge pull request pixelfed#2071 from pixelfed/staging
Browse files Browse the repository at this point in the history
Update ApiV1Controller
  • Loading branch information
dansup authored Feb 28, 2020
2 parents 7297917 + eeca1fb commit 7776cca
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions app/Http/Controllers/Api/ApiV1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,32 @@ public function accountUpdateCredentials(Request $request)
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);
Expand All @@ -233,22 +246,36 @@ public function accountFollowersById(Request $request, $id)
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);
}

Expand Down Expand Up @@ -1764,7 +1791,7 @@ public function statusUnshare(Request $request, $id)
abort_if(!in_array($status->scope, ['public','unlisted']), 403);
}
}

Status::whereProfileId($user->profile_id)
->whereReblogOfId($status->id)
->delete();
Expand Down

0 comments on commit 7776cca

Please sign in to comment.