]> git.mxchange.org Git - friendica.git/blob - src/Worker/APDelivery.php
798a9b49a1802fd732d4a0d49e4abf12a38a12b7
[friendica.git] / src / Worker / APDelivery.php
1 <?php
2 /**
3  * @file src/Worker/APDelivery.php
4  */
5 namespace Friendica\Worker;
6
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\Model\Item;
13 use Friendica\Util\HTTPSignature;
14
15 class APDelivery extends BaseObject
16 {
17         /**
18          * @brief Delivers ActivityPub messages
19          *
20          * @param string  $cmd
21          * @param integer $target_id
22          * @param string  $inbox
23          * @param integer $uid
24          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
25          * @throws \ImagickException
26          */
27         public static function execute($cmd, $target_id, $inbox, $uid)
28         {
29                 Logger::log('Invoked: ' . $cmd . ': ' . $target_id . ' to ' . $inbox, Logger::DEBUG);
30
31                 $success = true;
32
33                 if ($cmd == Delivery::MAIL) {
34                 } elseif ($cmd == Delivery::SUGGESTION) {
35                         $success = ActivityPub\Transmitter::sendContactSuggestion($uid, $inbox, $target_id);
36                 } elseif ($cmd == Delivery::RELOCATION) {
37                 } elseif ($cmd == Delivery::REMOVAL) {
38                         $success = ActivityPub\Transmitter::sendProfileDeletion($uid, $inbox);
39                 } elseif ($cmd == Delivery::PROFILEUPDATE) {
40                         $success = ActivityPub\Transmitter::sendProfileUpdate($uid, $inbox);
41                 } else {
42                         $data = ActivityPub\Transmitter::createCachedActivityFromItem($target_id);
43                         if (!empty($data)) {
44                                 $success = HTTPSignature::transmit($data, $inbox, $uid);
45                         }
46
47                         if ($success && in_array($cmd, [Delivery::POST, Delivery::COMMENT])) {
48                                 ItemDeliveryData::incrementQueueDone($target_id);
49                         }
50                 }
51
52                 if (!$success) {
53                         Worker::defer();
54                 }
55         }
56 }