]> git.mxchange.org Git - friendica.git/blob - src/Worker/APDelivery.php
New page for remote follow requests
[friendica.git] / src / Worker / APDelivery.php
1 <?php
2 /**
3  * @file src/Worker/APDelivery.php
4  */
5 namespace Friendica\Worker;
6
7 use Friendica\Core\Logger;
8 use Friendica\Core\Worker;
9 use Friendica\Model\ItemDeliveryData;
10 use Friendica\Protocol\ActivityPub;
11 use Friendica\Util\HTTPSignature;
12
13 class APDelivery
14 {
15         /**
16          * Delivers ActivityPub messages
17          *
18          * @param string  $cmd
19          * @param integer $target_id
20          * @param string  $inbox
21          * @param integer $uid
22          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
23          * @throws \ImagickException
24          */
25         public static function execute($cmd, $target_id, $inbox, $uid)
26         {
27                 Logger::log('Invoked: ' . $cmd . ': ' . $target_id . ' to ' . $inbox, Logger::DEBUG);
28
29                 $success = true;
30
31                 if ($cmd == Delivery::MAIL) {
32                         $data = ActivityPub\Transmitter::createActivityFromMail($target_id);
33                         if (!empty($data)) {
34                                 $success = HTTPSignature::transmit($data, $inbox, $uid);
35                         }
36                 } elseif ($cmd == Delivery::SUGGESTION) {
37                         $success = ActivityPub\Transmitter::sendContactSuggestion($uid, $inbox, $target_id);
38                 } elseif ($cmd == Delivery::RELOCATION) {
39                         // @todo Implementation pending
40                 } elseif ($cmd == Delivery::POKE) {
41                         // Implementation not planned
42                 } elseif ($cmd == Delivery::REMOVAL) {
43                         $success = ActivityPub\Transmitter::sendProfileDeletion($uid, $inbox);
44                 } elseif ($cmd == Delivery::PROFILEUPDATE) {
45                         $success = ActivityPub\Transmitter::sendProfileUpdate($uid, $inbox);
46                 } else {
47                         $data = ActivityPub\Transmitter::createCachedActivityFromItem($target_id);
48                         if (!empty($data)) {
49                                 $success = HTTPSignature::transmit($data, $inbox, $uid);
50                         }
51                 }
52
53                 if (!$success && !Worker::defer() && in_array($cmd, [Delivery::POST])) {
54                         ItemDeliveryData::incrementQueueFailed($target_id);
55                 } elseif ($success && in_array($cmd, [Delivery::POST])) {
56                         ItemDeliveryData::incrementQueueDone($target_id, ItemDeliveryData::ACTIVITYPUB);
57                 }
58         }
59 }