Update StatusDelete pipeline, fanout via AP if enabled

This commit is contained in:
Daniel Supernault 2019-03-05 18:06:23 -07:00
parent 6b2955561e
commit 66d525dde5
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 53 additions and 1 deletions

View file

@ -13,6 +13,10 @@ use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use League\Fractal;
use League\Fractal\Serializer\ArraySerializer;
use App\Transformer\ActivityPub\Verb\DeleteNote;
use App\Util\ActivityPub\Helpers;
class StatusDelete implements ShouldQueue
{
@ -46,7 +50,12 @@ class StatusDelete implements ShouldQueue
{
$status = $this->status;
$this->unlinkRemoveMedia($status);
if(config('pixelfed.activitypub_enabled') == true) {
$this->fanoutDelete($status);
} else {
$this->unlinkRemoveMedia($status);
}
}
public function unlinkRemoveMedia($status)
@ -87,4 +96,22 @@ class StatusDelete implements ShouldQueue
return true;
}
protected function fanoutDelete($status)
{
$audience = $status->profile->getAudienceInbox();
$profile = $status->profile;
$fractal = new Fractal\Manager();
$fractal->setSerializer(new ArraySerializer());
$resource = new Fractal\Resource\Item($status, new DeleteNote());
$activity = $fractal->createData($resource)->toArray();
$this->unlinkRemoveMedia($status);
foreach($audience as $url) {
Helpers::sendSignedObject($profile, $url, $activity);
}
}
}

View file

@ -0,0 +1,25 @@
<?php
namespace App\Transformer\ActivityPub\Verb;
use App\Status;
use League\Fractal;
class DeleteNote extends Fractal\TransformerAbstract
{
public function transform(Status $status)
{
'@context' => [
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1',
],
'id' => $status->permalink('#delete'),
'type' => 'Delete',
'actor' => $status->profile->permalink(),
'object' => [
'id' => $status->permalink()
'type' => 'Tombstone',
]
}
}