]> git.mxchange.org Git - friendica.git/commitdiff
Bookwyrm posts now work
authorMichael <heluecht@pirati.ca>
Sat, 23 Jul 2022 12:50:15 +0000 (12:50 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 23 Jul 2022 12:50:15 +0000 (12:50 +0000)
src/Model/APContact.php
src/Model/Item.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Receiver.php
src/Util/JsonLD.php

index ba2e3c9734fdff020a3dcc6e35958cb0f4f44ce1..841c028909b65c56913487844ce767fcf00a502e 100644 (file)
@@ -539,6 +539,13 @@ class APContact
                HTTPSignature::setInboxStatus($url, true, $shared);
        }
 
+       /**
+        * Check if the apcontact is a relay account
+        *
+        * @param array $apcontact
+        *
+        * @return bool 
+        */
        public static function isRelay(array $apcontact): bool
        {
                if ($apcontact['nick'] != 'relay') {
@@ -549,7 +556,7 @@ class APContact
                        return true;
                }
 
-               if (in_array($apcontact['type'], ['Group', 'Service']) && ($apcontact['nick'] == 'relay') && is_null($apcontact['outbox'])) {
+               if (in_array($apcontact['type'], ['Group', 'Service']) && is_null($apcontact['outbox'])) {
                        return true;
                }
 
index 414295356870625e471e2daa9b931d22ede90174..3ae23412e6e20689b5745f49b880740ed3e9e294 100644 (file)
@@ -683,19 +683,19 @@ class Item
                        'uri-id', 'parent-uri-id',
                        'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
                        'wall', 'private', 'origin', 'author-id'];
-               $condition = ['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid']];
+               $condition = ['uri-id' => [$item['thr-parent-id'], $item['parent-uri-id']], 'uid' => $item['uid']];
                $params = ['order' => ['id' => false]];
                $parent = Post::selectFirst($fields, $condition, $params);
 
-               if (!DBA::isResult($parent) && ($item['thr-parent-id'] != $item['parent-uri-id'])) {
-                       $condition = ['uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']];
-                       $parent = Post::selectFirst($fields, $condition, $params);
-               }
-
-               if (!DBA::isResult($parent) && $item['origin']) {
+               if (!DBA::isResult($parent) && Post::exists(['uri-id' => [$item['thr-parent-id'], $item['parent-uri-id']], 'uid' => 0])) {
                        $stored = Item::storeForUserByUriId($item['thr-parent-id'], $item['uid']);
-                       Logger::info('Stored thread parent item for user', ['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid'], 'stored' => $stored]);
-                       $parent = Post::selectFirst($fields, $condition, $params);
+                       if (!$stored && ($item['thr-parent-id'] != $item['parent-uri-id'])) {
+                               $stored = Item::storeForUserByUriId($item['parent-uri-id'], $item['uid']);
+                       }
+                       if ($stored) {
+                               Logger::info('Stored thread parent item for user', ['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid'], 'stored' => $stored]);
+                               $parent = Post::selectFirst($fields, $condition, $params);
+                       }
                }
 
                if (!DBA::isResult($parent)) {
@@ -908,7 +908,7 @@ class Item
                $item['contact-id'] = self::contactId($item);
 
                if (!empty($item['direction']) && in_array($item['direction'], [Conversation::PUSH, Conversation::RELAY]) &&
-                       empty($item['origin']) &&self::isTooOld($item)) {
+                       empty($item['origin']) && self::isTooOld($item)) {
                        Logger::info('Item is too old', ['item' => $item]);
                        return 0;
                }
index 28192d35bad46e29dfc8a687644925765e33bfe1..9c7cfef77d815351b16211befb9cebef56b0a264 100644 (file)
@@ -299,7 +299,7 @@ class Processor
                if (empty($activity['directmessage']) && ($activity['id'] != $activity['reply-to-id']) && !Post::exists(['uri' => $activity['reply-to-id']])) {
                        $recursion_depth = $activity['recursion-depth'] ?? 0;
                        Logger::notice('Parent not found. Try to refetch it.', ['parent' => $activity['reply-to-id'], 'recursion-depth' => $recursion_depth]);
-                       if ($recursion_depth < 10000) {
+                       if ($recursion_depth < 10) {
                                $result = self::fetchMissingActivity($activity['reply-to-id'], $activity, '', Receiver::COMPLETION_AUTO);
                                $fetch_by_worker = empty($result);
                        } else {
index 1cbd5c9e363c30845c6c351c0696b7c76d322485..92ed31922bf991d10f7ab806591080cbd23afd7b 100644 (file)
@@ -437,17 +437,18 @@ class Receiver
                $object_data['receiver'] = array_replace($object_data['receiver'] ?? [], $receivers);
                $object_data['reception_type'] = array_replace($object_data['reception_type'] ?? [], $reception_types);
 
-               $author = $object_data['author'] ?? $actor;
-               if (!empty($author) && !empty($object_data['id'])) {
-                       $author_host = parse_url($author, PHP_URL_HOST);
-                       $id_host = parse_url($object_data['id'], PHP_URL_HOST);
-                       if ($author_host == $id_host) {
-                               Logger::info('Valid hosts', ['type' => $type, 'host' => $id_host]);
-                       } else {
-                               Logger::notice('Differing hosts on author and id', ['type' => $type, 'author' => $author_host, 'id' => $id_host]);
-                               $trust_source = false;
-                       }
-               }
+//             This check here interferes with Hubzilla posts where the author host differs from the host the post was created
+//             $author = $object_data['author'] ?? $actor;
+//             if (!empty($author) && !empty($object_data['id'])) {
+//                     $author_host = parse_url($author, PHP_URL_HOST);
+//                     $id_host = parse_url($object_data['id'], PHP_URL_HOST);
+//                     if ($author_host == $id_host) {
+//                             Logger::info('Valid hosts', ['type' => $type, 'host' => $id_host]);
+//                     } else {
+//                             Logger::notice('Differing hosts on author and id', ['type' => $type, 'author' => $author_host, 'id' => $id_host]);
+//                             $trust_source = false;
+//                     }
+//             }
 
                Logger::info('Processing ' . $object_data['type'] . ' ' . $object_data['object_type'] . ' ' . $object_data['id']);
 
@@ -580,7 +581,16 @@ class Receiver
                }
        }
 
-       public static function routeActivities($object_data, $type, $push)
+       /**
+        * Route activities
+        *
+        * @param array   $object_data
+        * @param string  $type
+        * @param boolean $push
+        *
+        * @return boolean Could the activity be routed?
+        */
+       public static function routeActivities(array $object_data, string $type, bool $push): bool
        {
                $activity = $object_data['object_activity']     ?? [];
 
@@ -627,7 +637,7 @@ class Receiver
 
                                        $item = ActivityPub\Processor::createItem($object_data);
                                        if (empty($item)) {
-                                               return;
+                                               return false;
                                        }
 
                                        $item['post-reason'] = Item::PR_ANNOUNCEMENT;
index 1200a9cbed4a4c1a273e181646a15c042a8ac096..947274134ccf91c8c88a5edc5af4fb76ca2835c2 100644 (file)
@@ -177,6 +177,13 @@ class JsonLD
                        }
                }
 
+               // Bookwyrm transmits "id" fields with "null", which isn't allowed.
+               array_walk_recursive($json, function (&$value, $key) {
+                       if ($key == 'id' && is_null($value)) {
+                               $value = '';
+                       }
+               });
+
                $jsonobj = json_decode(json_encode($json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
 
                try {