1
0
Fork 0
forked from mirror/pixelfed
pixelfed/app/Jobs/FollowPipeline/FollowActivityPubDeliver.php

66 lines
1.6 KiB
PHP
Raw Normal View History

2019-01-01 06:27:07 +00:00
<?php
namespace App\Jobs\FollowPipeline;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
2019-12-11 06:04:03 +00:00
use Cache, Log;
use Illuminate\Support\Facades\Redis;
2019-01-01 06:27:07 +00:00
use League\Fractal;
use League\Fractal\Serializer\ArraySerializer;
use App\FollowRequest;
use App\Util\ActivityPub\Helpers;
use App\Transformer\ActivityPub\Verb\Follow;
class FollowActivityPubDeliver implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $followRequest;
2019-01-12 22:22:34 +00:00
/**
* Delete the job if its models no longer exist.
*
* @var bool
*/
public $deleteWhenMissingModels = true;
2019-01-01 06:27:07 +00:00
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(FollowRequest $followRequest)
{
$this->followRequest = $followRequest;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$follow = $this->followRequest;
$actor = $follow->actor;
$target = $follow->target;
2019-04-04 19:42:12 +00:00
if($target->domain == null || $target->inbox_url == null || !$actor->private_key) {
2019-01-01 06:27:07 +00:00
return;
}
$fractal = new Fractal\Manager();
$fractal->setSerializer(new ArraySerializer());
$resource = new Fractal\Resource\Item($follow, new Follow());
$activity = $fractal->createData($resource)->toArray();
$url = $target->sharedInbox ?? $target->inbox_url;
Helpers::sendSignedObject($actor, $url, $activity);
}
}