From: Michael Date: Sat, 23 Jul 2022 12:50:15 +0000 (+0000) Subject: Bookwyrm posts now work X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8c602071c2070b78c4780c2d0d72b4599b6483cb;p=friendica.git Bookwyrm posts now work --- diff --git a/src/Model/APContact.php b/src/Model/APContact.php index ba2e3c9734..841c028909 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -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; } diff --git a/src/Model/Item.php b/src/Model/Item.php index 4142953568..3ae23412e6 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -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; } diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 28192d35ba..9c7cfef77d 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -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 { diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php index 1cbd5c9e36..92ed31922b 100644 --- a/src/Protocol/ActivityPub/Receiver.php +++ b/src/Protocol/ActivityPub/Receiver.php @@ -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; diff --git a/src/Util/JsonLD.php b/src/Util/JsonLD.php index 1200a9cbed..947274134c 100644 --- a/src/Util/JsonLD.php +++ b/src/Util/JsonLD.php @@ -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 {