mirror of
https://github.com/YunoHost-Apps/pixelfed_ynh.git
synced 2024-09-03 20:06:04 +02: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'];
|
protected $fillable = ['profile_id', 'following_id', 'local_profile'];
|
||||||
|
|
||||||
|
const MAX_FOLLOWING = 7500;
|
||||||
|
const FOLLOW_PER_HOUR = 20;
|
||||||
|
|
||||||
public function actor()
|
public function actor()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Profile::class, 'profile_id', 'id');
|
return $this->belongsTo(Profile::class, 'profile_id', 'id');
|
||||||
|
|
|
@ -37,6 +37,8 @@ class FollowerController extends Controller
|
||||||
protected function handleFollowRequest($item)
|
protected function handleFollowRequest($item)
|
||||||
{
|
{
|
||||||
$user = Auth::user()->profile;
|
$user = Auth::user()->profile;
|
||||||
|
|
||||||
|
|
||||||
$target = Profile::where('id', '!=', $user->id)->whereNull('status')->findOrFail($item);
|
$target = Profile::where('id', '!=', $user->id)->whereNull('status')->findOrFail($item);
|
||||||
$private = (bool) $target->is_private;
|
$private = (bool) $target->is_private;
|
||||||
$remote = (bool) $target->domain;
|
$remote = (bool) $target->domain;
|
||||||
|
@ -47,7 +49,7 @@ class FollowerController extends Controller
|
||||||
->exists();
|
->exists();
|
||||||
|
|
||||||
if($blocked == true) {
|
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();
|
$isFollowing = Follower::whereProfileId($user->id)->whereFollowingId($target->id)->count();
|
||||||
|
@ -61,6 +63,13 @@ class FollowerController extends Controller
|
||||||
|
|
||||||
}
|
}
|
||||||
} elseif ($isFollowing == 0) {
|
} 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 = new Follower();
|
||||||
$follower->profile_id = $user->id;
|
$follower->profile_id = $user->id;
|
||||||
$follower->following_id = $target->id;
|
$follower->following_id = $target->id;
|
||||||
|
|
|
@ -211,6 +211,10 @@ export default {
|
||||||
notification.relationship.following = true;
|
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.addClass('btn-outline-secondary').removeClass('btn-primary');
|
||||||
el.text('Unfollow');
|
el.text('Unfollow');
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
swal(
|
if(err.response.data.message) {
|
||||||
'Whoops! Something went wrong…',
|
swal('Error', err.response.data.message, 'error');
|
||||||
'An error occurred, please try again later.',
|
}
|
||||||
'error'
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -950,6 +950,10 @@ export default {
|
||||||
this.profile.followers_count++;
|
this.profile.followers_count++;
|
||||||
}
|
}
|
||||||
this.relationship.following = !this.relationship.following;
|
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.following.splice(index, 1);
|
||||||
this.profile.following_count--;
|
this.profile.following_count--;
|
||||||
}
|
}
|
||||||
})
|
}).catch(err => {
|
||||||
|
if(err.response.data.message) {
|
||||||
|
swal('Error', err.response.data.message, 'error');
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
momentBackground() {
|
momentBackground() {
|
||||||
|
|
|
@ -148,6 +148,10 @@ export default {
|
||||||
item: id
|
item: id
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
window.location.href = window.location.href;
|
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
|
item: id
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
this.suggestions.splice(index, 1);
|
this.suggestions.splice(index, 1);
|
||||||
})
|
}).catch(err => {
|
||||||
|
if(err.response.data.message) {
|
||||||
|
swal('Error', err.response.data.message, 'error');
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
followModalAction(id, index, type = 'following') {
|
followModalAction(id, index, type = 'following') {
|
||||||
|
@ -1093,7 +1097,11 @@
|
||||||
if(type == 'following') {
|
if(type == 'following') {
|
||||||
this.following.splice(index, 1);
|
this.following.splice(index, 1);
|
||||||
}
|
}
|
||||||
})
|
}).catch(err => {
|
||||||
|
if(err.response.data.message) {
|
||||||
|
swal('Error', err.response.data.message, 'error');
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
owner(status) {
|
owner(status) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue