]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/Notifier.php
Fix storage backend class names
[friendica.git] / src / Worker / Notifier.php
index e0108ddcfef503a1abebf83c3e49dc0ea900bec2..fa0de8fb5ea883bd2fd15b11b1e9d5598640e084 100644 (file)
@@ -24,9 +24,6 @@ use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\OStatus;
 use Friendica\Protocol\Salmon;
 
-require_once 'include/dba.php';
-require_once 'include/items.php';
-
 /*
  * The notifier is typically called with:
  *
@@ -106,7 +103,7 @@ class Notifier
                        $inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser(0);
                        foreach ($inboxes as $inbox) {
                                Logger::log('Account removal for user ' . $item_id . ' to ' . $inbox .' via ActivityPub', Logger::DEBUG);
-                               Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
+                               Worker::add(['priority' => PRIORITY_NEGLIGIBLE, 'created' => $a->queue['created'], 'dont_fork' => true],
                                        'APDelivery', Delivery::REMOVAL, '', $inbox, $item_id);
                        }
 
@@ -127,7 +124,16 @@ class Notifier
                        }
 
                        $parent_id = intval($target_item['parent']);
-                       $uid = $target_item['contact-uid'];
+
+                       if (!empty($target_item['contact-uid'])) {
+                               $uid = $target_item['contact-uid'];
+                       } elseif (!empty($target_item['uid'])) {
+                               $uid = $target_item['uid'];
+                       } else {
+                               Logger::log('Only public users for item ' . $item_id, Logger::DEBUG);
+                               return;
+                       }
+
                        $updated = $target_item['edited'];
 
                        $condition = ['parent' => $parent_id, 'visible' => true, 'moderated' => false];
@@ -430,8 +436,9 @@ class Notifier
                                // The function will ensure that there are no duplicates
                                $r1 = Diaspora::participantsForThread($item_id, $r1);
 
-                               // Add the relay to the list, avoid duplicates
-                               if (!$followup) {
+                               // Add the relay to the list, avoid duplicates.
+                               // Don't send community posts to the relay. Forum posts via the Diaspora protocol are looking ugly.
+                               if (!$followup && !self::isForumPost($target_item, $owner)) {
                                        $r1 = Diaspora::relayList($item_id, $r1);
                                }
                        }
@@ -447,8 +454,16 @@ class Notifier
                                foreach ($r as $rr) {
                                        $conversants[] = $rr['id'];
                                        Logger::log('Public delivery of item ' . $target_item["guid"] . ' (' . $item_id . ') to ' . json_encode($rr), Logger::DEBUG);
-                                       Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
-                                               'Delivery', $cmd, $item_id, (int)$rr['id']);
+
+                                       // Ensure that posts with our own protocol arrives before Diaspora posts arrive.
+                                       // Situation is that sometimes Friendica servers receive Friendica posts over the Diaspora protocol first.
+                                       // The conversion in Markdown reduces the formatting, so these posts should arrive after the Friendica posts.
+                                       if ($rr['network'] == Protocol::DIASPORA) {
+                                               $deliver_options = ['priority' => $a->queue['priority'], 'dont_fork' => true];
+                                       } else {
+                                               $deliver_options = ['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true];
+                                       }
+                                       Worker::add($deliver_options, 'Delivery', $cmd, $item_id, (int)$rr['id']);
                                }
                        }
 
@@ -471,8 +486,16 @@ class Notifier
                                }
 
                                Logger::log('Delivery of item ' . $item_id . ' to ' . json_encode($contact), Logger::DEBUG);
-                               Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
-                                               'Delivery', $cmd, $item_id, (int)$contact['id']);
+
+                               // Ensure that posts with our own protocol arrives before Diaspora posts arrive.
+                               // Situation is that sometimes Friendica servers receive Friendica posts over the Diaspora protocol first.
+                               // The conversion in Markdown reduces the formatting, so these posts should arrive after the Friendica posts.
+                               if ($contact['network'] == Protocol::DIASPORA) {
+                                       $deliver_options = ['priority' => $a->queue['priority'], 'dont_fork' => true];
+                               } else {
+                                       $deliver_options = ['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true];
+                               }
+                               Worker::add($deliver_options, 'Delivery', $cmd, $item_id, (int)$contact['id']);
                        }
                }
 
@@ -511,7 +534,6 @@ class Notifier
        private static function activityPubDelivery($a, $cmd, $item_id, $uid, $target_item, $parent)
        {
                $inboxes = [];
-               $personal = false;
 
                if ($target_item['origin']) {
                        $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($target_item, $uid);
@@ -519,18 +541,13 @@ class Notifier
                } elseif (!DBA::exists('conversation', ['item-uri' => $target_item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB])) {
                        Logger::log('Remote item ' . $item_id . ' with URL ' . $target_item['uri'] . ' is no AP post. It will not be distributed.', Logger::DEBUG);
                        return;
-               } else {
+               } elseif ($parent['origin']) {
                        // Remote items are transmitted via the personal inboxes.
                        // Doing so ensures that the dedicated receiver will get the message.
-                       $personal = true;
+                       $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($parent, $uid, true, $item_id);
                        Logger::log('Remote item ' . $item_id . ' with URL ' . $target_item['uri'] . ' will be distributed.', Logger::DEBUG);
                }
 
-               if ($parent['origin']) {
-                       $parent_inboxes = ActivityPub\Transmitter::fetchTargetInboxes($parent, $uid, $personal);
-                       $inboxes = array_merge($inboxes, $parent_inboxes);
-               }
-
                if (empty($inboxes)) {
                        Logger::log('No inboxes found for item ' . $item_id . ' with URL ' . $target_item['uri'] . '. It will not be distributed.', Logger::DEBUG);
                        return;