]> git.mxchange.org Git - friendica.git/commitdiff
Simplyfies AP relaying, fixes relaying of public contacts
authorMichael <heluecht@pirati.ca>
Thu, 17 Jan 2019 23:06:27 +0000 (23:06 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 17 Jan 2019 23:06:27 +0000 (23:06 +0000)
src/Protocol/ActivityPub/Transmitter.php
src/Worker/Delivery.php
src/Worker/Notifier.php

index 04631aa2fbf3c27f56e6599b159719aa581f115c..05d0c458679b2550764469fd21bf3f807a75791e 100644 (file)
@@ -297,11 +297,16 @@ class Transmitter
         *
         * @param array $item
         * @param boolean $blindcopy
+        * @param boolean $last_id
         *
         * @return array with permission data
         */
-       private static function createPermissionBlockForItem($item, $blindcopy)
+       private static function createPermissionBlockForItem($item, $blindcopy, $last_id = 0)
        {
+               if ($last_id == 0) {
+                       $last_id = $item['id'];
+               }
+
                // Will be activated in a later step
                // $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
 
@@ -356,7 +361,7 @@ class Transmitter
                $parents = Item::select(['id', 'author-link', 'owner-link', 'gravity', 'uri'], ['parent' => $item['parent']]);
                while ($parent = Item::fetch($parents)) {
                        // Don't include data from future posts
-                       if ($parent['id'] >= $item['id']) {
+                       if ($parent['id'] >= $last_id) {
                                continue;
                        }
 
@@ -472,12 +477,13 @@ class Transmitter
         * @param array $item
         * @param integer $uid User ID
         * @param boolean $personal fetch personal inboxes
+        * @param integer $last_id Last item id for adding receivers
         *
         * @return array with inboxes
         */
-       public static function fetchTargetInboxes($item, $uid, $personal = false)
+       public static function fetchTargetInboxes($item, $uid, $personal = false, $last_id = 0)
        {
-               $permissions = self::createPermissionBlockForItem($item, true);
+               $permissions = self::createPermissionBlockForItem($item, true, $last_id);
                if (empty($permissions)) {
                        return [];
                }
@@ -643,9 +649,15 @@ class Transmitter
                        $data['object'] = $item['thr-parent'];
                }
 
-               $owner = User::getOwnerDataById($item['contact-uid']);
+               if (!empty($item['contact-uid'])) {
+                       $uid = $item['contact-uid'];
+               } else {
+                       $uid = $item['uid'];
+               }
 
-               if (!$object_mode) {
+               $owner = User::getOwnerDataById($uid);
+
+               if (!$object_mode && !empty($owner)) {
                        return LDSignature::sign($data, $owner);
                } else {
                        return $data;
index 459660f4ea795f1492107df8eda54890b8769392..c6d24657e5aad2fe6c54f17434c5429b41d5f22d 100644 (file)
@@ -88,7 +88,14 @@ class Delivery extends BaseObject
                                return;
                        }
 
-                       $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;
+                       }
 
                        // avoid race condition with deleting entries
                        if ($items[0]['deleted']) {
index d82e294d95ae2eccee8afd9bd7b08cac0da39dcc..e78920baedfddd63c6033bb5d92103df97fb1c09 100644 (file)
@@ -124,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];
@@ -508,7 +517,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);
@@ -516,18 +524,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;