]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/Notifier.php
Improvements to signature check, private posts do work now again
[friendica.git] / src / Worker / Notifier.php
index 401178ec26664090aa6478314d8812d9470113ae..286bcd03ee9be2e6afea22287fea902e11fe059c 100644 (file)
@@ -16,6 +16,7 @@ use Friendica\Model\Item;
 use Friendica\Model\PushSubscriber;
 use Friendica\Model\User;
 use Friendica\Network\Probe;
+use Friendica\Protocol\ActivityPub;
 use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\OStatus;
 use Friendica\Protocol\Salmon;
@@ -96,7 +97,7 @@ class Notifier
                                return;
                        }
                        foreach ($r as $contact) {
-                               Contact::terminateFriendship($user, $contact);
+                               Contact::terminateFriendship($user, $contact, true);
                        }
                        return;
                } elseif ($cmd == Delivery::RELOCATION) {
@@ -217,24 +218,16 @@ class Notifier
                        }
 
                        // Special treatment for forum posts
-                       if (($target_item['author-id'] != $target_item['owner-id']) &&
-                               ($owner['id'] != $target_item['contact-id']) &&
-                               ($target_item['uri'] === $target_item['parent-uri'])) {
-
-                               $fields = ['forum', 'prv'];
-                               $condition = ['id' => $target_item['contact-id']];
-                               $contact = DBA::selectFirst('contact', $fields, $condition);
-                               if (!DBA::isResult($contact)) {
-                                       // Should never happen
-                                       return false;
-                               }
+                       if (self::isForumPost($target_item, $owner)) {
+                               $relay_to_owner = true;
+                               $direct_forum_delivery = true;
+                       }
 
-                               // Is the post from a forum?
-                               if ($contact['forum'] || $contact['prv']) {
-                                       $relay_to_owner = true;
-                                       $direct_forum_delivery = true;
-                               }
+                       // Avoid that comments in a forum thread are sent to OStatus
+                       if (self::isForumPost($parent, $owner)) {
+                               $direct_forum_delivery = true;
                        }
+
                        if ($relay_to_owner) {
                                // local followup to remote post
                                $followup = true;
@@ -421,6 +414,24 @@ class Notifier
                        }
                }
 
+               $inboxes = [];
+
+               if ($target_item['origin']) {
+                       $inboxes = ActivityPub::fetchTargetInboxes($target_item, $uid);
+               }
+
+               if ($parent['origin']) {
+                       $parent_inboxes = ActivityPub::fetchTargetInboxes($parent, $uid);
+                       $inboxes = array_merge($inboxes, $parent_inboxes);
+               }
+
+               foreach ($inboxes as $inbox) {
+                       logger('Deliver ' . $item_id .' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG);
+
+                       Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
+                                       'APDelivery', $cmd, $item_id, $inbox);
+               }
+
                // send salmon slaps to mentioned remote tags (@foo@example.com) in OStatus posts
                // They are especially used for notifications to OStatus users that don't follow us.
                if (!Config::get('system', 'dfrn_only') && count($url_recipients) && ($public_message || $push_notify) && $normal_mode) {
@@ -504,4 +515,23 @@ class Notifier
 
                return;
        }
+
+       private static function isForumPost($item, $owner) {
+               if (($item['author-id'] == $item['owner-id']) ||
+                       ($owner['id'] == $item['contact-id']) ||
+                       ($item['uri'] != $item['parent-uri'])) {
+                       return false;
+               }
+
+               $fields = ['forum', 'prv'];
+               $condition = ['id' => $item['contact-id']];
+               $contact = DBA::selectFirst('contact', $fields, $condition);
+               if (!DBA::isResult($contact)) {
+                       // Should never happen
+                       return false;
+               }
+
+               // Is the post from a forum?
+               return ($contact['forum'] || $contact['prv']);
+       }
 }