mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Add limits to Following
This commit is contained in:
parent
44ba4749f9
commit
d1c0e9aae9
7 changed files with 43 additions and 9 deletions
|
@ -9,6 +9,9 @@ class Follower extends Model
|
|||
|
||||
protected $fillable = ['profile_id', 'following_id', 'local_profile'];
|
||||
|
||||
const MAX_FOLLOWING = 7500;
|
||||
const FOLLOW_PER_HOUR = 20;
|
||||
|
||||
public function actor()
|
||||
{
|
||||
return $this->belongsTo(Profile::class, 'profile_id', 'id');
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -211,6 +211,10 @@ export default {
|
|||
notification.relationship.following = true;
|
||||
}
|
||||
});
|
||||
}).catch(err => {
|
||||
if(err.response.data.message) {
|
||||
swal('Error', err.response.data.message, 'error');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -73,11 +73,9 @@ export default {
|
|||
el.addClass('btn-outline-secondary').removeClass('btn-primary');
|
||||
el.text('Unfollow');
|
||||
}).catch(err => {
|
||||
swal(
|
||||
'Whoops! Something went wrong…',
|
||||
'An error occurred, please try again later.',
|
||||
'error'
|
||||
);
|
||||
if(err.response.data.message) {
|
||||
swal('Error', err.response.data.message, 'error');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -950,6 +950,10 @@ export default {
|
|||
this.profile.followers_count++;
|
||||
}
|
||||
this.relationship.following = !this.relationship.following;
|
||||
}).catch(err => {
|
||||
if(err.response.data.message) {
|
||||
swal('Error', err.response.data.message, 'error');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -1064,7 +1068,11 @@ export default {
|
|||
this.following.splice(index, 1);
|
||||
this.profile.following_count--;
|
||||
}
|
||||
})
|
||||
}).catch(err => {
|
||||
if(err.response.data.message) {
|
||||
swal('Error', err.response.data.message, 'error');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
momentBackground() {
|
||||
|
|
|
@ -148,6 +148,10 @@ export default {
|
|||
item: id
|
||||
}).then(res => {
|
||||
window.location.href = window.location.href;
|
||||
}).catch(err => {
|
||||
if(err.response.data.message) {
|
||||
swal('Error', err.response.data.message, 'error');
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
|
|
|
@ -1083,7 +1083,11 @@
|
|||
item: id
|
||||
}).then(res => {
|
||||
this.suggestions.splice(index, 1);
|
||||
})
|
||||
}).catch(err => {
|
||||
if(err.response.data.message) {
|
||||
swal('Error', err.response.data.message, 'error');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
followModalAction(id, index, type = 'following') {
|
||||
|
@ -1093,7 +1097,11 @@
|
|||
if(type == 'following') {
|
||||
this.following.splice(index, 1);
|
||||
}
|
||||
})
|
||||
}).catch(err => {
|
||||
if(err.response.data.message) {
|
||||
swal('Error', err.response.data.message, 'error');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
owner(status) {
|
||||
|
|
Loading…
Reference in a new issue