]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Delivery.php
Remove parameter-less call of OStatus\Salmon module in DFRN\Notify
[friendica.git] / src / Protocol / ActivityPub / Delivery.php
index c959d8c615bd2f6058888ff1f4e631627cfd0b82..add898888f9d5f994932d6691ded4841718e9f67 100644 (file)
 namespace Friendica\Protocol\ActivityPub;
 
 use Friendica\Core\Logger;
+use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\GServer;
+use Friendica\Model\Item;
 use Friendica\Model\Post;
 use Friendica\Protocol\ActivityPub;
 use Friendica\Util\HTTPSignature;
@@ -52,9 +54,10 @@ class Delivery
                                if ($result['serverfailure']) {
                                        // In a timeout situation we assume that every delivery to that inbox will time out.
                                        // So we set the flag and try all deliveries at a later time.
-                                       Logger::info('Inbox delivery has a server failure', ['inbox' => $inbox]);
+                                       Logger::notice('Inbox delivery has a server failure', ['inbox' => $inbox]);
                                        $serverfail = true;
                                }
+                               Worker::coolDown();
                        }
 
                        if ($serverfail || (!$result['success'] && !$result['drop'])) {
@@ -80,11 +83,15 @@ class Delivery
        public static function deliverToInbox(string $cmd, int $item_id, string $inbox, int $uid, array $receivers, int $uri_id): array
        {
                if (empty($item_id) && !empty($uri_id) && !empty($uid)) {
-                       $item = Post::selectFirst(['id', 'parent', 'origin'], ['uri-id' => $uri_id, 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
+                       $item = Post::selectFirst(['id', 'parent', 'origin', 'gravity', 'verb'], ['uri-id' => $uri_id, 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
                        if (empty($item['id'])) {
-                               Logger::notice('Item not found, removing delivery', ['uri-id' => $uri_id, 'uid' => $uid, 'cmd' => $cmd, 'inbox' => $inbox]);
+                               Logger::warning('Item not found, removing delivery', ['uri-id' => $uri_id, 'uid' => $uid, 'cmd' => $cmd, 'inbox' => $inbox]);
                                Post\Delivery::remove($uri_id, $inbox);
-                               return true;
+                               return ['success' => true, 'serverfailure' => false, 'drop' => false];
+                       } elseif (!DI::config()->get('system', 'redistribute_activities') && !$item['origin'] && ($item['gravity'] == Item::GRAVITY_ACTIVITY)) {
+                               Logger::notice('Activities are not relayed, removing delivery', ['verb' => $item['verb'], 'uri-id' => $uri_id, 'uid' => $uid, 'cmd' => $cmd, 'inbox' => $inbox]);
+                               Post\Delivery::remove($uri_id, $inbox);
+                               return ['success' => true, 'serverfailure' => false, 'drop' => false];
                        } else {
                                $item_id = $item['id'];
                        }
@@ -103,8 +110,6 @@ class Delivery
                        $success = ActivityPub\Transmitter::sendContactSuggestion($uid, $inbox, $item_id);
                } elseif ($cmd == WorkerDelivery::RELOCATION) {
                        // @todo Implementation pending
-               } elseif ($cmd == WorkerDelivery::POKE) {
-                       // Implementation not planned
                } elseif ($cmd == WorkerDelivery::REMOVAL) {
                        $success = ActivityPub\Transmitter::sendProfileDeletion($uid, $inbox);
                } elseif ($cmd == WorkerDelivery::PROFILEUPDATE) {
@@ -144,11 +149,16 @@ class Delivery
                                                if (!empty($actor)) {
                                                        $drop = !ActivityPub\Transmitter::sendRelayFollow($actor);
                                                        Logger::notice('Resubscribed to relay', ['url' => $actor, 'success' => !$drop]);
+                                               } elseif ($cmd = WorkerDelivery::DELETION) {
+                                                       // Remote systems not always accept our deletion requests, so we drop them if rejected.
+                                                       // Situation is: In Friendica we allow the thread owner to delete foreign comments to their thread.
+                                                       // Most AP systems don't allow this, so they will reject the deletion request.
+                                                       $drop = true;
                                                }
 
                                        }
 
-                                       Logger::info('Delivery failed', ['retcode' => $response->getReturnCode(), 'serverfailure' => $serverfail, 'drop' => $drop, 'runtime' => round($runtime, 3), 'uri-id' => $uri_id, 'uid' => $uid, 'item_id' => $item_id, 'cmd' => $cmd, 'inbox' => $inbox]);
+                                       Logger::notice('Delivery failed', ['retcode' => $response->getReturnCode(), 'serverfailure' => $serverfail, 'drop' => $drop, 'runtime' => round($runtime, 3), 'uri-id' => $uri_id, 'uid' => $uid, 'item_id' => $item_id, 'cmd' => $cmd, 'inbox' => $inbox]);
                                }
                                if ($uri_id) {
                                        if ($success) {
@@ -157,14 +167,16 @@ class Delivery
                                                Post\Delivery::incrementFailed($uri_id, $inbox);
                                        }
                                }
+                       } elseif ($uri_id) {
+                               Post\Delivery::remove($uri_id, $inbox);
                        }
                }
 
                self::setSuccess($receivers, $success);
 
-               Logger::debug('Delivered', ['uri-id' => $uri_id, 'uid' => $uid, 'item_id' => $item_id, 'cmd' => $cmd, 'inbox' => $inbox, 'success' => $success]);
+               Logger::debug('Delivered', ['uri-id' => $uri_id, 'uid' => $uid, 'item_id' => $item_id, 'cmd' => $cmd, 'inbox' => $inbox, 'success' => $success, 'serverfailure' => $serverfail, 'drop' => $drop]);
 
-               if ($success && in_array($cmd, [WorkerDelivery::POST])) {
+               if (($success || $drop) && in_array($cmd, [WorkerDelivery::POST])) {
                        Post\DeliveryData::incrementQueueDone($uri_id, Post\DeliveryData::ACTIVITYPUB);
                }
 
@@ -179,7 +191,8 @@ class Delivery
         */
        private static function fetchActorForRelayInbox(string $inbox): string
        {
-               $apcontact = DBA::selectFirst('apcontact', ['url'], ['sharedinbox' => $inbox, 'type' => 'Application']);
+               $apcontact = DBA::selectFirst('apcontact', ['url'], ["`sharedinbox` = ? AND `type` = ? AND `url` IN (SELECT `url` FROM `contact` WHERE `uid` = ? AND `rel` = ?)",
+                       $inbox, 'Application', 0, Contact::FRIEND]);
                return $apcontact['url'] ?? '';
        }