Add limits to Following
This commit is contained in:
parent
44ba4749f9
commit
d1c0e9aae9
7 changed files with 43 additions and 9 deletions
|
@ -37,6 +37,8 @@ class FollowerController extends Controller
|
|||
protected function handleFollowRequest($item)
|
||||
{
|
||||
$user = Auth::user()->profile;
|
||||
|
||||
|
||||
$target = Profile::where('id', '!=', $user->id)->whereNull('status')->findOrFail($item);
|
||||
$private = (bool) $target->is_private;
|
||||
$remote = (bool) $target->domain;
|
||||
|
@ -47,7 +49,7 @@ class FollowerController extends Controller
|
|||
->exists();
|
||||
|
||||
if($blocked == true) {
|
||||
return redirect()->back()->with('error', 'You cannot follow this user.');
|
||||
abort(400, 'You cannot follow this user.');
|
||||
}
|
||||
|
||||
$isFollowing = Follower::whereProfileId($user->id)->whereFollowingId($target->id)->count();
|
||||
|
@ -61,6 +63,13 @@ class FollowerController extends Controller
|
|||
|
||||
}
|
||||
} elseif ($isFollowing == 0) {
|
||||
if($user->following()->count() >= Follower::MAX_FOLLOWING) {
|
||||
abort(400, 'You cannot follow more than ' . Follower::MAX_FOLLOWING . ' accounts');
|
||||
}
|
||||
|
||||
if($user->following()->where('followers.created_at', '>', now()->subHour())->count() >= Follower::FOLLOW_PER_HOUR) {
|
||||
abort(400, 'You can only follow ' . Follower::FOLLOW_PER_HOUR . ' users per hour');
|
||||
}
|
||||
$follower = new Follower();
|
||||
$follower->profile_id = $user->id;
|
||||
$follower->following_id = $target->id;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue