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