From 01239cb9bedfb78c338571d4ed41b20bb1b8436e Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 5 Sep 2019 20:40:40 -0600 Subject: [PATCH] Update AP Inbox --- app/Util/ActivityPub/Inbox.php | 69 +++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 10 deletions(-) diff --git a/app/Util/ActivityPub/Inbox.php b/app/Util/ActivityPub/Inbox.php index 48a0ab50d..6d08c1906 100644 --- a/app/Util/ActivityPub/Inbox.php +++ b/app/Util/ActivityPub/Inbox.php @@ -10,7 +10,8 @@ use App\{ Like, Notification, Profile, - Status + Status, + StatusHashtag, }; use Carbon\Carbon; use App\Util\ActivityPub\Helpers; @@ -285,28 +286,74 @@ class Inbox public function handleDeleteActivity() { + if(!isset( + $this->payload['actor'], + $this->payload['object'], + $this->payload['object']['id'] + $this->payload['object']['type'] + )) { + return; + } $actor = $this->payload['actor']; $obj = $this->payload['object']; - abort_if(!Helpers::validateUrl($obj), 400); - if(is_string($obj) && Helpers::validateUrl($obj)) { - // actor object detected - // todo delete actor + $type = $this->payload['object']['type']; + $typeCheck = in_array($type, ['Person', 'Tombstone']); + if(!Helpers::validateUrl($actor) || !Helpers::validateUrl($obj) || !$typeCheck) { return; - } else if (Helpers::validateUrl($obj['id']) && Helpers::validateObject($obj) && $obj['type'] == 'Tombstone') { - // todo delete status or object + } + if(parse_url($obj['id'], PHP_URL_HOST) !== parse_url($actor, PHP_URL_HOST)) { return; } + $id = $this->payload['object']['id']; + switch ($type) { + case 'Person': + $profile = Profile::whereNull('domain') + ->whereNull('private_key') + ->whereRemoteUrl($id) + ->first(); + if(!$profile) { + return; + } + Notification::whereActorId($profile->id)->delete(); + $profile->avatar()->delete(); + $profile->followers()->delete(); + $profile->following()->delete(); + $profile->likes()->delete(); + $profile->media()->delete(); + $profile->statuses()->delete(); + $profile->delete(); + return; + break; + + case 'Tombstone': + $status = Status::whereUri($id)->first(); + if(!$status) { + return; + } + $status->media->delete(); + $status->delete(); + return; + break; + + default: + return; + break; + } } public function handleLikeActivity() { $actor = $this->payload['actor']; - abort_if(!Helpers::validateUrl($actor), 400); + if(!Helpers::validateUrl($actor)) { + return; + } $profile = self::actorFirstOrCreate($actor); $obj = $this->payload['object']; - abort_if(!Helpers::validateLocalUrl($obj), 400); + if(!Helpers::validateUrl($obj)) { + return; + } $status = Helpers::statusFirstOrFetch($obj); if(!$status || !$profile) { return; @@ -343,7 +390,9 @@ class Inbox case 'Announce': $obj = $obj['object']; - abort_if(!Helpers::validateLocalUrl($obj), 400); + if(!Helpers::validateLocalUrl($obj)) { + return; + } $status = Helpers::statusFetch($obj); if(!$status) { return;