]> git.mxchange.org Git - friendica.git/commitdiff
Additional checks against fetch loops
authorMichael <heluecht@pirati.ca>
Wed, 14 Aug 2024 05:17:39 +0000 (05:17 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 15 Aug 2024 04:35:46 +0000 (04:35 +0000)
src/Protocol/ActivityPub/Queue.php
src/Protocol/ActivityPub/Receiver.php

index a9918e5ea0927d61909674036451a7da5692cc86..c084b337858f168cb06f8e64e0ab26f682e0ed59 100644 (file)
@@ -189,10 +189,11 @@ class Queue
         *
         * @param integer $id
         * @param bool    $fetch_parents
+        * @param array   $parent
         *
         * @return bool
         */
-       public static function process(int $id, bool $fetch_parents = true): bool
+       public static function process(int $id, bool $fetch_parents = true, array $parent = []): bool
        {
                $entry = DBA::selectFirst('inbox-entry', [], ['id' => $id]);
                if (empty($entry)) {
@@ -226,6 +227,14 @@ class Queue
                $activity['worker-id']       = $entry['wid'];
                $activity['recursion-depth'] = 0;
 
+               if (!empty($parent['children'])) {
+                       $activity['children'] = array_merge($activity['children'] ?? [], $parent['children']);
+               }
+
+               if (!empty($parent['callstack'])) {
+                       $activity['callstack'] = array_merge($activity['callstack'] ?? [], $parent['callstack']);
+               }
+
                if (empty($activity['thread-children-type'])) {
                        $activity['thread-children-type'] = $type;
                }
@@ -349,15 +358,16 @@ class Queue
         * Process all activities that are children of a given post url
         *
         * @param string $uri
+        * @param array  $parent
         * @return int
         */
-       public static function processReplyByUri(string $uri): int
+       public static function processReplyByUri(string $uri, array $parent = []): int
        {
                $count = 0;
                $entries = DBA::select('inbox-entry', ['id'], ["`in-reply-to-id` = ? AND `object-id` != ?", $uri, $uri]);
                while ($entry = DBA::fetch($entries)) {
                        $count += 1;
-                       self::process($entry['id'], false);
+                       self::process($entry['id'], false, $parent);
                }
                DBA::close($entries);
                return $count;
index 39090df4136de6d28827a4c40e22add8edfa1e02..2b93a13d3ba6ae2bef856882429f5b3ae3eb1e01 100644 (file)
@@ -728,6 +728,9 @@ class Receiver
                        self::addArrivedId($object_data['object_id']);
                }
 
+               $object_data['children']  = $activity['children'] ?? [];
+               $object_data['callstack'] = $activity['callstack'] ?? [];
+
                $decouple = DI::config()->get('system', 'decoupled_receiver') && !in_array($completion, [self::COMPLETION_MANUAL, self::COMPLETION_ANNOUNCE]) && empty($object_data['directmessage']);
 
                if ($decouple && ($trust_source || DI::config()->get('debug', 'ap_inbox_store_untrusted'))) {
@@ -756,9 +759,6 @@ class Receiver
                        $object_data['recursion-depth'] = $activity['recursion-depth'];
                }
 
-               $object_data['children']  = $activity['children'] ?? [];
-               $object_data['callstack'] = $activity['callstack'] ?? [];
-
                if (!self::routeActivities($object_data, $type, $push, true, $uid)) {
                        self::storeUnhandledActivity(true, $type, $object_data, $activity, $body, $uid, $trust_source, $push, $signer);
                        Queue::remove($object_data);