mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-29 09:43:16 +00:00
Update ApiV1Controller, fix account settings bug
This commit is contained in:
parent
75a44fdc2f
commit
08246f2482
3 changed files with 127 additions and 103 deletions
|
@ -411,34 +411,40 @@ class ApiV1Controller extends Controller
|
||||||
public function accountFollowersById(Request $request, $id)
|
public function accountFollowersById(Request $request, $id)
|
||||||
{
|
{
|
||||||
abort_if(!$request->user(), 403);
|
abort_if(!$request->user(), 403);
|
||||||
|
$account = AccountService::get($id);
|
||||||
|
abort_if(!$account, 404);
|
||||||
|
$pid = $request->user()->profile_id;
|
||||||
|
|
||||||
$user = $request->user();
|
if($pid != $account['id']) {
|
||||||
$profile = Profile::whereNull('status')->findOrFail($id);
|
if($account['locked']) {
|
||||||
$limit = $request->input('limit') ?? 40;
|
if(FollowerService::follows($pid, $account['id'])) {
|
||||||
|
return [];
|
||||||
if($profile->domain) {
|
|
||||||
$res = [];
|
|
||||||
} else {
|
|
||||||
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 {
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(AccountService::hiddenFollowers($id)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($request->has('page') && $request->page >= 5) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$res = DB::table('followers')
|
||||||
|
->select('id', 'profile_id', 'following_id')
|
||||||
|
->whereFollowingId($account['id'])
|
||||||
|
->orderByDesc('id')
|
||||||
|
->simplePaginate(10)
|
||||||
|
->map(function($follower) {
|
||||||
|
return AccountService::getMastodon($follower->profile_id);
|
||||||
|
})
|
||||||
|
->filter(function($account) {
|
||||||
|
return $account && isset($account['id']);
|
||||||
|
})
|
||||||
|
->values()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
return response()->json($res);
|
return response()->json($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,36 +457,40 @@ class ApiV1Controller extends Controller
|
||||||
*/
|
*/
|
||||||
public function accountFollowingById(Request $request, $id)
|
public function accountFollowingById(Request $request, $id)
|
||||||
{
|
{
|
||||||
abort_if(!$request->user(), 403);
|
abort_if(!$request->user(), 403);
|
||||||
|
$account = AccountService::get($id);
|
||||||
|
abort_if(!$account, 404);
|
||||||
|
$pid = $request->user()->profile_id;
|
||||||
|
|
||||||
$user = $request->user();
|
if($pid != $account['id']) {
|
||||||
$profile = Profile::whereNull('status')->findOrFail($id);
|
if($account['locked']) {
|
||||||
$limit = $request->input('limit') ?? 40;
|
if(FollowerService::follows($pid, $account['id'])) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if($profile->domain) {
|
if(AccountService::hiddenFollowing($id)) {
|
||||||
$res = [];
|
return [];
|
||||||
} else {
|
}
|
||||||
if($profile->id == $user->profile_id) {
|
|
||||||
$following = $profile->following()->paginate($limit);
|
if($request->has('page') && $request->page >= 5) {
|
||||||
$resource = new Fractal\Resource\Collection($following, new AccountTransformer());
|
return [];
|
||||||
$res = $this->fractal->createData($resource)->toArray();
|
|
||||||
} else {
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$res = DB::table('followers')
|
||||||
|
->select('id', 'profile_id', 'following_id')
|
||||||
|
->whereProfileId($account['id'])
|
||||||
|
->orderByDesc('id')
|
||||||
|
->simplePaginate(10)
|
||||||
|
->map(function($follower) {
|
||||||
|
return AccountService::get($follower->following_id);
|
||||||
|
})
|
||||||
|
->filter(function($account) {
|
||||||
|
return $account && isset($account['id']);
|
||||||
|
})
|
||||||
|
->values()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
return response()->json($res);
|
return response()->json($res);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ use App\{
|
||||||
StatusView,
|
StatusView,
|
||||||
UserFilter
|
UserFilter
|
||||||
};
|
};
|
||||||
use Auth, Cache;
|
use Auth, Cache, DB;
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Illuminate\Support\Facades\Redis;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use League\Fractal;
|
use League\Fractal;
|
||||||
|
@ -651,70 +651,82 @@ class PublicApiController extends Controller
|
||||||
|
|
||||||
public function accountFollowers(Request $request, $id)
|
public function accountFollowers(Request $request, $id)
|
||||||
{
|
{
|
||||||
abort_unless(Auth::check(), 403);
|
abort_if(!$request->user(), 403);
|
||||||
$profile = Profile::with('user')->whereNull('status')->findOrFail($id);
|
$account = AccountService::get($id);
|
||||||
$owner = Auth::id() == $profile->user_id;
|
abort_if(!$account, 404);
|
||||||
|
$pid = $request->user()->profile_id;
|
||||||
|
|
||||||
if(Auth::id() != $profile->user_id && $profile->is_private) {
|
if($pid != $account['id']) {
|
||||||
return response()->json([]);
|
if($account['locked']) {
|
||||||
}
|
if(FollowerService::follows($pid, $account['id'])) {
|
||||||
if(!$profile->domain && !$profile->user->settings->show_profile_followers) {
|
return [];
|
||||||
return response()->json([]);
|
}
|
||||||
}
|
}
|
||||||
if(!$owner && $request->page > 5) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$res = Follower::select('id', 'profile_id', 'following_id')
|
if(AccountService::hiddenFollowers($id)) {
|
||||||
->whereFollowingId($profile->id)
|
return [];
|
||||||
->orderByDesc('id')
|
}
|
||||||
->simplePaginate(10)
|
|
||||||
->map(function($follower) {
|
|
||||||
return ProfileService::get($follower['profile_id']);
|
|
||||||
})
|
|
||||||
->toArray();
|
|
||||||
|
|
||||||
return response()->json($res);
|
if($request->has('page') && $request->page >= 5) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$res = DB::table('followers')
|
||||||
|
->select('id', 'profile_id', 'following_id')
|
||||||
|
->whereFollowingId($account['id'])
|
||||||
|
->orderByDesc('id')
|
||||||
|
->simplePaginate(10)
|
||||||
|
->map(function($follower) {
|
||||||
|
return AccountService::get($follower->profile_id);
|
||||||
|
})
|
||||||
|
->filter(function($account) {
|
||||||
|
return $account && isset($account['id']);
|
||||||
|
})
|
||||||
|
->values()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
return response()->json($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function accountFollowing(Request $request, $id)
|
public function accountFollowing(Request $request, $id)
|
||||||
{
|
{
|
||||||
abort_unless(Auth::check(), 403);
|
abort_if(!$request->user(), 403);
|
||||||
|
$account = AccountService::get($id);
|
||||||
|
abort_if(!$account, 404);
|
||||||
|
$pid = $request->user()->profile_id;
|
||||||
|
|
||||||
$profile = Profile::with('user')
|
if($pid != $account['id']) {
|
||||||
->whereNull('status')
|
if($account['locked']) {
|
||||||
->findOrFail($id);
|
if(FollowerService::follows($pid, $account['id'])) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// filter by username
|
if(AccountService::hiddenFollowing($id)) {
|
||||||
$search = $request->input('fbu');
|
return [];
|
||||||
$owner = Auth::id() == $profile->user_id;
|
}
|
||||||
$filter = ($owner == true) && ($search != null);
|
|
||||||
|
|
||||||
abort_if($owner == false && $profile->is_private == true && !$profile->followedBy(Auth::user()->profile), 404);
|
if($request->has('page') && $request->page >= 5) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!$profile->domain) {
|
$res = DB::table('followers')
|
||||||
abort_if($profile->user->settings->show_profile_following == false && $owner == false, 404);
|
->select('id', 'profile_id', 'following_id')
|
||||||
}
|
->whereProfileId($account['id'])
|
||||||
|
->orderByDesc('id')
|
||||||
|
->simplePaginate(10)
|
||||||
|
->map(function($follower) {
|
||||||
|
return AccountService::get($follower->following_id);
|
||||||
|
})
|
||||||
|
->filter(function($account) {
|
||||||
|
return $account && isset($account['id']);
|
||||||
|
})
|
||||||
|
->values()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
if(!$owner && $request->page > 5) {
|
return response()->json($res);
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if($search) {
|
|
||||||
abort_if(!$owner, 404);
|
|
||||||
$following = $profile->following()
|
|
||||||
->where('profiles.username', 'like', '%'.$search.'%')
|
|
||||||
->orderByDesc('followers.created_at')
|
|
||||||
->paginate(10);
|
|
||||||
} else {
|
|
||||||
$following = $profile->following()
|
|
||||||
->orderByDesc('followers.created_at')
|
|
||||||
->paginate(10);
|
|
||||||
}
|
|
||||||
$resource = new Fractal\Resource\Collection($following, new AccountTransformer());
|
|
||||||
$res = $this->fractal->createData($resource)->toArray();
|
|
||||||
|
|
||||||
return response()->json($res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function accountStatuses(Request $request, $id)
|
public function accountStatuses(Request $request, $id)
|
||||||
|
|
|
@ -77,6 +77,8 @@ trait PrivacySettings
|
||||||
Cache::forget('profile:follower_count:' . $profile->id);
|
Cache::forget('profile:follower_count:' . $profile->id);
|
||||||
Cache::forget('profile:following_count:' . $profile->id);
|
Cache::forget('profile:following_count:' . $profile->id);
|
||||||
Cache::forget('profile:embed:' . $profile->id);
|
Cache::forget('profile:embed:' . $profile->id);
|
||||||
|
Cache::forget('pf:acct:settings:hidden-followers:' . $profile->id);
|
||||||
|
Cache::forget('pf:acct:settings:hidden-following:' . $profile->id);
|
||||||
return redirect(route('settings.privacy'))->with('status', 'Settings successfully updated!');
|
return redirect(route('settings.privacy'))->with('status', 'Settings successfully updated!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,4 +227,4 @@ trait PrivacySettings
|
||||||
Cache::forget('profiles:private');
|
Cache::forget('profiles:private');
|
||||||
return [200];
|
return [200];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue