]> git.mxchange.org Git - friendica.git/blob - src/Worker/APDelivery.php
Update item-uri with guid if given
[friendica.git] / src / Worker / APDelivery.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Worker;
23
24 use Friendica\Core\Logger;
25 use Friendica\Core\Worker;
26 use Friendica\Model\ItemDeliveryData;
27 use Friendica\Protocol\ActivityPub;
28 use Friendica\Util\HTTPSignature;
29
30 class APDelivery
31 {
32         /**
33          * Delivers ActivityPub messages
34          *
35          * @param string  $cmd
36          * @param integer $target_id
37          * @param string  $inbox
38          * @param integer $uid
39          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
40          * @throws \ImagickException
41          */
42         public static function execute($cmd, $target_id, $inbox, $uid)
43         {
44                 Logger::log('Invoked: ' . $cmd . ': ' . $target_id . ' to ' . $inbox, Logger::DEBUG);
45
46                 $success = true;
47
48                 if ($cmd == Delivery::MAIL) {
49                         $data = ActivityPub\Transmitter::createActivityFromMail($target_id);
50                         if (!empty($data)) {
51                                 $success = HTTPSignature::transmit($data, $inbox, $uid);
52                         }
53                 } elseif ($cmd == Delivery::SUGGESTION) {
54                         $success = ActivityPub\Transmitter::sendContactSuggestion($uid, $inbox, $target_id);
55                 } elseif ($cmd == Delivery::RELOCATION) {
56                         // @todo Implementation pending
57                 } elseif ($cmd == Delivery::POKE) {
58                         // Implementation not planned
59                 } elseif ($cmd == Delivery::REMOVAL) {
60                         $success = ActivityPub\Transmitter::sendProfileDeletion($uid, $inbox);
61                 } elseif ($cmd == Delivery::PROFILEUPDATE) {
62                         $success = ActivityPub\Transmitter::sendProfileUpdate($uid, $inbox);
63                 } else {
64                         $data = ActivityPub\Transmitter::createCachedActivityFromItem($target_id);
65                         if (!empty($data)) {
66                                 $success = HTTPSignature::transmit($data, $inbox, $uid);
67                         }
68                 }
69
70                 if (!$success && !Worker::defer() && in_array($cmd, [Delivery::POST])) {
71                         ItemDeliveryData::incrementQueueFailed($target_id);
72                 } elseif ($success && in_array($cmd, [Delivery::POST])) {
73                         ItemDeliveryData::incrementQueueDone($target_id, ItemDeliveryData::ACTIVITYPUB);
74                 }
75         }
76 }