*/ public function middleware(): array { return [ new WithoutOverlapping('move-send-unfollow:'.$this->follower->id.':actor:'.$this->actor), (new ThrottlesExceptions(2, 5 * 60))->backoff(5), ]; } /** * Create a new job instance. */ public function __construct($follower, $targetInbox, $targetPid, $actor) { $this->follower = $follower; $this->targetInbox = $targetInbox; $this->targetPid = $targetPid; $this->actor = $actor; } /** * Execute the job. */ public function handle(): void { $follower = $this->follower; $targetPid = $this->targetPid; $targetInbox = $this->targetInbox; $actor = $this->actor; // Verify follower and actor exists if (! $follower) { Log::info('MoveSendUndoFollowPipeline: Follower no longer exists, skipping job'); return; } if (! $actor) { Log::info('MoveSendUndoFollowPipeline: Actor no longer exists, skipping job'); return; } // Verify follower username and private_key exists if (! $follower->username) { Log::info('MoveSendUndoFollowPipeline: Follower may no longer exists, skipping job'); return; } if (! $follower->private_key) { Log::info('MoveSendUndoFollowPipeline: Follower may no longer exists, skipping job'); return; } $permalink = 'https://'.config('pixelfed.domain.app').'/users/'.$follower->username; $version = config('pixelfed.version'); $appUrl = config('app.url'); $userAgent = "(Pixelfed/{$version}; +{$appUrl})"; $addlHeaders = [ 'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', 'User-Agent' => $userAgent, ]; $activity = [ '@context' => 'https://www.w3.org/ns/activitystreams', 'type' => 'Undo', 'id' => $permalink.'#follow/'.$targetPid.'/undo', 'actor' => $permalink, 'object' => [ 'type' => 'Follow', 'id' => $permalink.'#follows/'.$targetPid, 'object' => $actor, 'actor' => $permalink, ], ]; $keyId = $permalink.'#main-key'; $payload = json_encode($activity); $curlHeaders = HttpSignature::signRaw($follower->private_key, $keyId, $targetInbox, $activity, $addlHeaders); $headers = []; foreach ($curlHeaders as $header) { $parts = explode(': ', $header, 2); if (count($parts) === 2) { $headers[$parts[0]] = $parts[1]; } } try { Http::withHeaders($headers) ->timeout(config('federation.activitypub.delivery.timeout')) ->withBody($payload, 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"') ->post($targetInbox); } catch (ConnectionException $e) { } } }