Update AP Inbox

This commit is contained in:
Daniel Supernault 2019-09-05 20:40:40 -06:00
parent a30575e8d3
commit 01239cb9be
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -10,7 +10,8 @@ use App\{
Like, Like,
Notification, Notification,
Profile, Profile,
Status Status,
StatusHashtag,
}; };
use Carbon\Carbon; use Carbon\Carbon;
use App\Util\ActivityPub\Helpers; use App\Util\ActivityPub\Helpers;
@ -285,28 +286,74 @@ class Inbox
public function handleDeleteActivity() public function handleDeleteActivity()
{ {
if(!isset(
$this->payload['actor'],
$this->payload['object'],
$this->payload['object']['id']
$this->payload['object']['type']
)) {
return;
}
$actor = $this->payload['actor']; $actor = $this->payload['actor'];
$obj = $this->payload['object']; $obj = $this->payload['object'];
abort_if(!Helpers::validateUrl($obj), 400); $type = $this->payload['object']['type'];
if(is_string($obj) && Helpers::validateUrl($obj)) { $typeCheck = in_array($type, ['Person', 'Tombstone']);
// actor object detected if(!Helpers::validateUrl($actor) || !Helpers::validateUrl($obj) || !$typeCheck) {
// todo delete actor
return; 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; 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() public function handleLikeActivity()
{ {
$actor = $this->payload['actor']; $actor = $this->payload['actor'];
abort_if(!Helpers::validateUrl($actor), 400); if(!Helpers::validateUrl($actor)) {
return;
}
$profile = self::actorFirstOrCreate($actor); $profile = self::actorFirstOrCreate($actor);
$obj = $this->payload['object']; $obj = $this->payload['object'];
abort_if(!Helpers::validateLocalUrl($obj), 400); if(!Helpers::validateUrl($obj)) {
return;
}
$status = Helpers::statusFirstOrFetch($obj); $status = Helpers::statusFirstOrFetch($obj);
if(!$status || !$profile) { if(!$status || !$profile) {
return; return;
@ -343,7 +390,9 @@ class Inbox
case 'Announce': case 'Announce':
$obj = $obj['object']; $obj = $obj['object'];
abort_if(!Helpers::validateLocalUrl($obj), 400); if(!Helpers::validateLocalUrl($obj)) {
return;
}
$status = Helpers::statusFetch($obj); $status = Helpers::statusFetch($obj);
if(!$status) { if(!$status) {
return; return;