Update FollowerController, send Follow ActivityPub object to remote instances

This commit is contained in:
Daniel Supernault 2019-06-10 21:30:01 -06:00
parent a0a77f4de4
commit f0455b0454
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
1 changed files with 30 additions and 3 deletions

View File

@ -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);
}
}