X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FWorker%2FAPDelivery.php;h=203c4097612d97fd04812d0dae80c8c57c50bfb3;hb=9fbdcb5459e4acb158961427837612999253e046;hp=df9df8128a4fefb736fc3c0f8d1852c430d291b9;hpb=74167043a8fdbcc8d98f11297e427d73508313fe;p=friendica.git diff --git a/src/Worker/APDelivery.php b/src/Worker/APDelivery.php index df9df8128a..203c409761 100644 --- a/src/Worker/APDelivery.php +++ b/src/Worker/APDelivery.php @@ -23,12 +23,8 @@ namespace Friendica\Worker; use Friendica\Core\Logger; use Friendica\Core\Worker; -use Friendica\Model\Contact; -use Friendica\Model\GServer; use Friendica\Model\Post; use Friendica\Protocol\ActivityPub; -use Friendica\Util\HTTPSignature; - class APDelivery { /** @@ -65,116 +61,25 @@ class APDelivery return; } - Logger::info('Invoked', ['cmd' => $cmd, 'inbox' => $inbox, 'id' => $item_id, 'uri-id' => $uri_id, 'uid' => $uid]); + Logger::debug('Invoked', ['cmd' => $cmd, 'inbox' => $inbox, 'id' => $item_id, 'uri-id' => $uri_id, 'uid' => $uid]); if (empty($uri_id)) { - $result = self::deliver($inbox); + $result = ActivityPub\Delivery::deliver($inbox); $success = $result['success']; + $drop = false; $uri_ids = $result['uri_ids']; } else { - $success = self::deliverToInbox($cmd, $item_id, $inbox, $uid, $receivers, $uri_id); + $result = ActivityPub\Delivery::deliverToInbox($cmd, $item_id, $inbox, $uid, $receivers, $uri_id); + $success = $result['success']; + $drop = $result['drop']; $uri_ids = [$uri_id]; } - if (!$success && !Worker::defer() && !empty($uri_ids)) { + if (!$drop && !$success && !Worker::defer() && !empty($uri_ids)) { foreach ($uri_ids as $uri_id) { Post\Delivery::remove($uri_id, $inbox); Post\DeliveryData::incrementQueueFailed($uri_id); } } } - - private static function deliver(string $inbox) - { - $uri_ids = []; - $posts = Post\Delivery::selectForInbox($inbox); - - foreach ($posts as $post) { - if (!self::deliverToInbox($post['command'], 0, $inbox, $post['uid'], $post['receivers'], $post['uri-id'])) { - $uri_ids[] = $post['uri-id']; - } - } - - Logger::debug('Inbox delivery done', ['inbox' => $inbox, 'posts' => count($posts), 'failed' => count($uri_ids)]); - return ['success' => empty($uri_ids), 'uri_ids' => $uri_ids]; - } - - private static function deliverToInbox(string $cmd, int $item_id, string $inbox, int $uid, array $receivers, int $uri_id) - { - if (empty($item_id) && !empty($uri_id) && !empty($uid)) { - $item = Post::selectFirst(['id', 'parent', 'origin'], ['uri-id' => $uri_id, 'uid' => [$uid, 0]], ['order' => ['uid' => true]]); - if (empty($item['id'])) { - Logger::debug('Item not found, removing delivery', ['uri-id' => $uri_id, 'uid' => $uid, 'cmd' => $cmd, 'inbox' => $inbox]); - Post\Delivery::remove($uri_id, $inbox); - return true; - } else { - $item_id = $item['id']; - } - } - - $success = true; - - if ($cmd == Delivery::MAIL) { - $data = ActivityPub\Transmitter::createActivityFromMail($item_id); - if (!empty($data)) { - $success = HTTPSignature::transmit($data, $inbox, $uid); - } - } elseif ($cmd == Delivery::SUGGESTION) { - $success = ActivityPub\Transmitter::sendContactSuggestion($uid, $inbox, $item_id); - } elseif ($cmd == Delivery::RELOCATION) { - // @todo Implementation pending - } elseif ($cmd == Delivery::POKE) { - // Implementation not planned - } elseif ($cmd == Delivery::REMOVAL) { - $success = ActivityPub\Transmitter::sendProfileDeletion($uid, $inbox); - } elseif ($cmd == Delivery::PROFILEUPDATE) { - $success = ActivityPub\Transmitter::sendProfileUpdate($uid, $inbox); - } else { - $data = ActivityPub\Transmitter::createCachedActivityFromItem($item_id); - if (!empty($data)) { - $success = HTTPSignature::transmit($data, $inbox, $uid); - if ($uri_id) { - if ($success) { - Post\Delivery::remove($uri_id, $inbox); - } else { - Post\Delivery::incrementFailed($uri_id, $inbox); - } - } - } - } - - self::setSuccess($receivers, $success); - - Logger::info('Delivered', ['uri-id' => $uri_id, 'uid' => $uid, 'item_id' => $item_id, 'cmd' => $cmd, 'inbox' => $inbox, 'success' => $success]); - - if ($success && in_array($cmd, [Delivery::POST])) { - Post\DeliveryData::incrementQueueDone($uri_id, Post\DeliveryData::ACTIVITYPUB); - } - - return $success; - } - - private static function setSuccess(array $receivers, bool $success) - { - $gsid = null; - - foreach ($receivers as $receiver) { - $contact = Contact::getById($receiver); - if (empty($contact)) { - continue; - } - - $gsid = $gsid ?: $contact['gsid']; - - if ($success) { - Contact::unmarkForArchival($contact); - } else { - Contact::markForArchival($contact); - } - } - - if (!empty($gsid)) { - GServer::setProtocol($gsid, Post\DeliveryData::ACTIVITYPUB); - } - } }