From 2078bb10c9ce2d7c3a27e45b945a85229f3a0860 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 24 Feb 2019 20:07:43 -0700 Subject: [PATCH 1/2] Update ActivityPub Inbox --- app/Util/ActivityPub/Inbox.php | 52 ++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/app/Util/ActivityPub/Inbox.php b/app/Util/ActivityPub/Inbox.php index e38cf3e00..adbb727f2 100644 --- a/app/Util/ActivityPub/Inbox.php +++ b/app/Util/ActivityPub/Inbox.php @@ -248,7 +248,28 @@ class Inbox public function handleAcceptActivity() { - + $actor = $this->payload['actor']; + $obj = $this->payload['object']; + switch ($obj['type']) { + case 'Follow': + $accept = [ + '@context' => 'https://www.w3.org/ns/activitystreams', + 'id' => $target->permalink().'#accepts/follows/' . $follower->id, + 'type' => 'Accept', + 'actor' => $target->permalink(), + 'object' => [ + 'id' => $actor->permalink('#follows/'.$target->id), + 'type' => 'Follow', + 'actor' => $actor->permalink(), + 'object' => $target->permalink() + ] + ]; + break; + + default: + # code... + break; + } } public function handleDeleteActivity() @@ -298,11 +319,7 @@ class Inbox $obj = $this->payload['object']; switch ($obj['type']) { - case 'Like': - $status = Helpers::statusFirstOrFetch($obj['object']); - Like::whereProfileId($profile->id) - ->whereStatusId($status->id) - ->forceDelete(); + case 'Accept': break; case 'Announce': @@ -318,6 +335,29 @@ class Inbox ->forceDelete(); $status->forceDelete(); break; + + case 'Block': + break; + + case 'Follow': + $following = self::actorFirstOrCreate($obj['object']); + Follower::whereProfileId($profile->id) + ->whereFollowingId($following->id) + ->delete(); + break; + + case 'Like': + $status = Helpers::statusFirstOrFetch($obj['object']); + Like::whereProfileId($profile->id) + ->whereStatusId($status->id) + ->forceDelete(); + Notification::whereProfileId($status->profile->id) + ->whereActorId($profile->id) + ->whereAction('like') + ->whereItemId($status->id) + ->whereItemType('App\Status') + ->forceDelete(); + break; } } From 77c056e93bf3da1e9a5272e7a08a942ea61d1340 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 24 Feb 2019 20:17:01 -0700 Subject: [PATCH 2/2] Update ActivityPub Inbox --- app/Util/ActivityPub/Inbox.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/app/Util/ActivityPub/Inbox.php b/app/Util/ActivityPub/Inbox.php index adbb727f2..244eb2aad 100644 --- a/app/Util/ActivityPub/Inbox.php +++ b/app/Util/ActivityPub/Inbox.php @@ -185,19 +185,18 @@ class Inbox 'following_id' => $target->id, 'local_profile' => empty($actor->domain) ]); - if($follower->wasRecentlyCreated == false) { - return; + if($follower->wasRecentlyCreated == true) { + // send notification + Notification::firstOrCreate([ + 'profile_id' => $target->id, + 'actor_id' => $actor->id, + 'action' => 'follow', + 'message' => $follower->toText(), + 'rendered' => $follower->toHtml(), + 'item_id' => $target->id, + 'item_type' => 'App\Profile' + ]); } - // send notification - Notification::firstOrCreate([ - 'profile_id' => $target->id, - 'actor_id' => $actor->id, - 'action' => 'follow', - 'message' => $follower->toText(), - 'rendered' => $follower->toHtml(), - 'item_id' => $target->id, - 'item_type' => 'App\Profile' - ]); // send Accept to remote profile $accept = [