3 * @file src/Worker/APDelivery.php
5 namespace Friendica\Worker;
7 use Friendica\BaseObject;
8 use Friendica\Core\Logger;
9 use Friendica\Core\Worker;
10 use Friendica\Model\ItemDeliveryData;
11 use Friendica\Protocol\ActivityPub;
12 use Friendica\Util\HTTPSignature;
14 class APDelivery extends BaseObject
17 * @brief Delivers ActivityPub messages
20 * @param integer $target_id
21 * @param string $inbox
23 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
24 * @throws \ImagickException
26 public static function execute($cmd, $target_id, $inbox, $uid)
28 Logger::log('Invoked: ' . $cmd . ': ' . $target_id . ' to ' . $inbox, Logger::DEBUG);
32 if ($cmd == Delivery::MAIL) {
33 $data = ActivityPub\Transmitter::createActivityFromMail($target_id);
35 $success = HTTPSignature::transmit($data, $inbox, $uid);
37 } elseif ($cmd == Delivery::SUGGESTION) {
38 $success = ActivityPub\Transmitter::sendContactSuggestion($uid, $inbox, $target_id);
39 } elseif ($cmd == Delivery::RELOCATION) {
40 // @todo Implementation pending
41 } elseif ($cmd == Delivery::POKE) {
42 // Implementation not planned
43 } elseif ($cmd == Delivery::REMOVAL) {
44 $success = ActivityPub\Transmitter::sendProfileDeletion($uid, $inbox);
45 } elseif ($cmd == Delivery::PROFILEUPDATE) {
46 $success = ActivityPub\Transmitter::sendProfileUpdate($uid, $inbox);
48 $data = ActivityPub\Transmitter::createCachedActivityFromItem($target_id);
50 $success = HTTPSignature::transmit($data, $inbox, $uid);
54 if (!$success && !Worker::defer() && in_array($cmd, [Delivery::POST])) {
55 ItemDeliveryData::incrementQueueFailed($target_id);
56 } elseif ($success && in_array($cmd, [Delivery::POST])) {
57 ItemDeliveryData::incrementQueueDone($target_id, ItemDeliveryData::ACTIVITYPUB);