]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/Notifier.php
New function to fetch the database driver
[friendica.git] / src / Worker / Notifier.php
index 17aaed57238672f939a84ebc08ea30e782a00987..d6cf0c2ff84aef4072bc131b26aa2497f4d0e54d 100644 (file)
@@ -179,7 +179,7 @@ class Notifier
 
                        // Only deliver threaded replies (comment to a comment) to Diaspora
                        // when the original comment author does support the Diaspora protocol.
-                       if ($target_item['parent-uri'] != $target_item['thr-parent']) {
+                       if ($thr_parent['author-link'] && $target_item['parent-uri'] != $target_item['thr-parent']) {
                                $diaspora_delivery = Diaspora::isSupportedByContactUrl($thr_parent['author-link']);
                                Logger::info('Threaded comment', ['diaspora_delivery' => (int)$diaspora_delivery]);
                        }
@@ -629,12 +629,12 @@ class Notifier
                }
 
                // Skip the delivery to Diaspora if the item is from an ActivityPub author
-               if ($item['author-network'] == Protocol::ACTIVITYPUB) {
+               if (!empty($item['author-network']) && ($item['author-network'] == Protocol::ACTIVITYPUB)) {
                        return true;
                }
-               
+
                // Skip the delivery to Diaspora if the thread parent is from an ActivityPub author
-               if ($thr_parent['author-network'] == Protocol::ACTIVITYPUB) {
+               if (!empty($thr_parent['author-network']) && ($thr_parent['author-network'] == Protocol::ACTIVITYPUB)) {
                        return true;
                }
 
@@ -685,17 +685,17 @@ class Notifier
                        return false;
                }
 
+               // We deliver reshares via AP whenever possible
+               if (ActivityPub\Transmitter::isAnnounce($item)) {
+                       return true;
+               }
+
                // For the time being we always deliver forum post via DFRN if possible
                // This can be removed possible at the end of 2020 when hopefully most system can process AP forum posts
                if ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) {
                        return false;
                }
 
-               // We deliver reshares via AP whenever possible
-               if (ActivityPub\Transmitter::isAnnounce($item)) {
-                       return true;
-               }
-
                // Skip DFRN when the item will be (forcefully) delivered via AP
                if (DI::config()->get('debug', 'total_ap_delivery') && ($contact['network'] == Protocol::DFRN) && !empty(APContact::getByURL($contact['url'], false))) {
                        return true;
@@ -781,11 +781,17 @@ class Notifier
                }
 
                $inboxes = [];
+               $relay_inboxes = [];
 
                $uid = $target_item['contact-uid'] ?: $target_item['uid'];
 
                if ($target_item['origin']) {
                        $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($target_item, $uid);
+
+                       if (in_array($target_item['private'], [Item::PUBLIC])) {
+                               $relay_inboxes = ActivityPub\Transmitter::addRelayServerInboxes();
+                       }
+
                        Logger::log('Origin item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' will be distributed.', Logger::DEBUG);
                } elseif (Item::isForumPost($target_item, $owner)) {
                        $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($target_item, $uid, false, 0, true);
@@ -797,10 +803,15 @@ class Notifier
                        // Remote items are transmitted via the personal inboxes.
                        // Doing so ensures that the dedicated receiver will get the message.
                        $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($parent, $uid, true, $target_item['id']);
+
+                       if (in_array($target_item['private'], [Item::PUBLIC])) {
+                               $relay_inboxes = ActivityPub\Transmitter::addRelayServerInboxes([]);
+                       }
+
                        Logger::log('Remote item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' will be distributed.', Logger::DEBUG);
                }
 
-               if (empty($inboxes)) {
+               if (empty($inboxes) && empty($relay_inboxes)) {
                        Logger::log('No inboxes found for item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . '. It will not be distributed.', Logger::DEBUG);
                        return 0;
                }
@@ -819,6 +830,15 @@ class Notifier
                        }
                }
 
+               // We deliver posts to relay servers slightly delayed to priorize the direct delivery
+               foreach ($relay_inboxes as $inbox) {
+                       Logger::info('Delivery to relay servers via ActivityPub', ['cmd' => $cmd, 'id' => $target_item['id'], 'inbox' => $inbox]);
+
+                       if (Worker::add(['priority' => $priority, 'dont_fork' => true], 'APDelivery', $cmd, $target_item['id'], $inbox, $uid)) {
+                               $delivery_queue_count++;
+                       }
+               }
+
                return $delivery_queue_count;
        }