]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Diaspora.php
Merge pull request #8629 from annando/item-insert
[friendica.git] / src / Protocol / Diaspora.php
index 708f5335a53d5d4525ef3d86bfb662c8eb749108..dd1f678d58945a22f3651f9001ab04f845b7af3a 100644 (file)
@@ -252,24 +252,27 @@ class Diaspora
         * One of the parameters is a contact array.
         * This is done to avoid duplicates.
         *
-        * @param array $parent   The parent post
+        * @param array $item     Item that is about to be delivered
         * @param array $contacts The previously fetched contacts
         *
         * @return array of relay servers
         * @throws \Exception
         */
-       public static function participantsForThread(array $parent, array $contacts)
+       public static function participantsForThread(array $item, array $contacts)
        {
-               if (!in_array($parent['private'], [Item::PUBLIC, Item::UNLISTED])) {
+               if (!in_array($item['private'], [Item::PUBLIC, Item::UNLISTED]) || in_array($item["verb"], [Activity::FOLLOW, Activity::TAG])) {
+                       Logger::info('Item is private or a participation request. It will not be relayed', ['guid' => $item['guid'], 'private' => $item['private'], 'verb' => $item['verb']]);
                        return $contacts;
                }
 
-               $items = Item::select(['author-id'], ['parent' => $parent['id']], ['group_by' => ['author-id']]);
+               $items = Item::select(['author-id', 'author-link', 'parent-author-link', 'parent-guid', 'guid'],
+                       ['parent' => $item['parent'], 'gravity' => [GRAVITY_COMMENT, GRAVITY_ACTIVITY]]);
                while ($item = DBA::fetch($items)) {
                        $contact = DBA::selectFirst('contact', ['id', 'url', 'name', 'protocol', 'batch', 'network'],
                                ['id' => $item['author-id']]);
-                       if (!DBA::isResult($contact)) {
-                               // Shouldn't happen
+                       if (!DBA::isResult($contact) || empty($contact['batch']) ||
+                               ($contact['network'] != Protocol::DIASPORA) ||
+                               Strings::compareLink($item['parent-author-link'], $item['author-link'])) {
                                continue;
                        }
 
@@ -281,7 +284,7 @@ class Diaspora
                        }
 
                        if (!$exists) {
-                               Logger::info('Add participant to receiver list', ['item' => $parent['guid'], 'participant' => $contact['url']]);
+                               Logger::info('Add participant to receiver list', ['parent' => $item['parent-guid'], 'item' => $item['guid'], 'participant' => $contact['url']]);
                                $contacts[] = $contact;
                        }
                }
@@ -2281,6 +2284,10 @@ class Diaspora
                        return false;
                }
 
+               if (!$parent_item['origin']) {
+                       Logger::info('Not our origin. Participation is ignored', ['parent_guid' => $parent_guid, 'guid' => $guid, 'author' => $author]);
+               }
+
                if (!in_array($parent_item['private'], [Item::PUBLIC, Item::UNLISTED])) {
                        Logger::info('Item is not public, participation is ignored', ['parent_guid' => $parent_guid, 'guid' => $guid, 'author' => $author]);
                        return false;
@@ -2325,9 +2332,10 @@ class Diaspora
                Logger::info('Participation stored', ['id' => $message_id, 'guid' => $guid, 'parent_guid' => $parent_guid, 'author' => $author]);
 
                // Send all existing comments and likes to the requesting server
-               $comments = Item::select(['id', 'uri-id', 'parent'], ['parent' => $parent_item['id']]);
+               $comments = Item::select(['id', 'uri-id', 'parent', 'verb'], ['parent' => $parent_item['id'], 'gravity' => [GRAVITY_COMMENT, GRAVITY_ACTIVITY]]);
                while ($comment = Item::fetch($comments)) {
-                       if ($comment['id'] == $comment['parent']) {
+                       if (in_array($comment["verb"], [Activity::FOLLOW, Activity::TAG])) {
+                               Logger::info('participation messages are not relayed', ['item' => $comment['id']]);
                                continue;
                        }