mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Update FollowerController, send Follow ActivityPub object to remote instances
This commit is contained in:
parent
a0a77f4de4
commit
f0455b0454
1 changed files with 30 additions and 3 deletions
|
@ -11,6 +11,7 @@ use App\{
|
|||
use Auth, Cache;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Jobs\FollowPipeline\FollowPipeline;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
|
||||
class FollowerController extends Controller
|
||||
{
|
||||
|
@ -55,13 +56,21 @@ class FollowerController extends Controller
|
|||
$isFollowing = Follower::whereProfileId($user->id)->whereFollowingId($target->id)->count();
|
||||
|
||||
if($private == true && $isFollowing == 0 || $remote == true) {
|
||||
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');
|
||||
}
|
||||
|
||||
$follow = FollowRequest::firstOrCreate([
|
||||
'follower_id' => $user->id,
|
||||
'following_id' => $target->id
|
||||
]);
|
||||
if($remote == true) {
|
||||
|
||||
}
|
||||
if($remote == true && config('federation.activitypub.remoteFollow') == true) {
|
||||
$this->sendFollow($user, $target);
|
||||
}
|
||||
} elseif ($isFollowing == 0) {
|
||||
if($user->following()->count() >= Follower::MAX_FOLLOWING) {
|
||||
abort(400, 'You cannot follow more than ' . Follower::MAX_FOLLOWING . ' accounts');
|
||||
|
@ -88,4 +97,22 @@ class FollowerController extends Controller
|
|||
Cache::forget('user:account:id:'.$target->user_id);
|
||||
Cache::forget('user:account:id:'.$user->user_id);
|
||||
}
|
||||
|
||||
protected function sendFollow($user, $target)
|
||||
{
|
||||
if($target->domain == null || $user->domain != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$payload = [
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'type' => 'Follow',
|
||||
'actor' => $user->permalink(),
|
||||
'object' => $target->permalink()
|
||||
];
|
||||
|
||||
$inbox = $target->sharedInbox ?? $target->inbox_url;
|
||||
|
||||
Helpers::sendSignedObject($user, $inbox, $payload);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue