From fee25d44e0a074b1aceba13e8b5e41f9e623ee55 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 21 May 2020 16:45:51 -0600 Subject: [PATCH] Update Inbox handler, remove logger --- app/Util/ActivityPub/Inbox.php | 44 ++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/app/Util/ActivityPub/Inbox.php b/app/Util/ActivityPub/Inbox.php index 10b548411..025ea88e6 100644 --- a/app/Util/ActivityPub/Inbox.php +++ b/app/Util/ActivityPub/Inbox.php @@ -42,12 +42,12 @@ class Inbox { $this->handleVerb(); - if(!Activity::where('data->id', $this->payload['id'])->exists()){ - (new Activity())->create([ - 'to_id' => $this->profile->id, - 'data' => json_encode($this->payload) - ]); - } + // if(!Activity::where('data->id', $this->payload['id'])->exists()) { + // (new Activity())->create([ + // 'to_id' => $this->profile->id, + // 'data' => json_encode($this->payload) + // ]); + // } return; @@ -62,6 +62,7 @@ class Inbox break; case 'Follow': + if(FollowValidator::validate($this->payload) == false) { return; } $this->handleFollowActivity(); break; @@ -80,6 +81,7 @@ class Inbox break; case 'Like': + if(LikeValidator::validate($this->payload) == false) { return; } $this->handleLikeActivity(); break; @@ -171,26 +173,32 @@ class Inbox public function handleFollowActivity() { $actor = $this->actorFirstOrCreate($this->payload['actor']); - if(!$actor || $actor->domain == null) { + $target = $this->profile; + if(!$actor || $actor->domain == null || $target->domain !== null) { + return; + } + if( + Follower::whereProfileId($actor->id) + ->whereFollowingId($target->id) + ->exists() || + FollowRequest::whereFollowerId($actor->id) + ->whereFollowingId($target->id) + ->exists(); + ) { return; } - $target = $this->profile; if($target->is_private == true) { - // make follow request FollowRequest::firstOrCreate([ 'follower_id' => $actor->id, 'following_id' => $target->id ]); - // todo: send notification } else { - // store new follower - $follower = Follower::firstOrCreate([ - 'profile_id' => $actor->id, - 'following_id' => $target->id, - 'local_profile' => empty($actor->domain) - ]); - if($follower->wasRecentlyCreated == true && $target->domain == null) { - // send notification + $follower = new Follower; + $follower->profile_id => $actor->id; + $follower->following_id => $target->id; + $follower->local_profile => empty($actor->domain); + + if($target->domain == null) { Notification::firstOrCreate([ 'profile_id' => $target->id, 'actor_id' => $actor->id,