1
0
Fork 0
forked from mirror/pixelfed

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,
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;