From 4982839c5a3d807c76b59a6a2415f821e2ef7113 Mon Sep 17 00:00:00 2001 From: Shlee Date: Sat, 29 Aug 2026 12:38:17 +0930 Subject: [PATCH] Update DeduplicationChanges.md --- notes/DeduplicationChanges.md | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/notes/DeduplicationChanges.md b/notes/DeduplicationChanges.md index 2d9e3be60..599928729 100644 --- a/notes/DeduplicationChanges.md +++ b/notes/DeduplicationChanges.md @@ -1,3 +1,47 @@ +# ActivityPub Delivery boilerplate +- `ActivityPubDeliveryService::pool($profile, $audience, $activity);` + +replaces +``` + $payload = json_encode($activity); + + $client = new Client([ + 'timeout' => config('federation.activitypub.delivery.timeout'), + ]); + + $version = config('pixelfed.version'); + $appUrl = config('app.url'); + $userAgent = "(Pixelfed/{$version}; +{$appUrl})"; + + $requests = function ($audience) use ($client, $activity, $profile, $payload, $userAgent) { + foreach ($audience as $url) { + $headers = HttpSignature::sign($profile, $url, $activity, [ + 'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + 'User-Agent' => $userAgent, + ]); + yield function () use ($client, $url, $headers, $payload) { + return $client->postAsync($url, [ + 'curl' => [ + CURLOPT_HTTPHEADER => $headers, + CURLOPT_POSTFIELDS => $payload, + CURLOPT_HEADER => true, + ], + ]); + }; + } + }; + + $pool = new Pool($client, $requests($audience), [ + 'concurrency' => config('federation.activitypub.delivery.concurrency'), + 'fulfilled' => function ($response, $index) {}, + 'rejected' => function ($reason, $index) {}, + ]); + + $promise = $pool->promise(); + + $promise->wait(); +``` + # Username validation boilerplate - `new ValidUsername,` replaces