Bookwyrm posts now work

This commit is contained in:
Michael 2022-07-23 12:50:15 +00:00
parent 7eb410bed7
commit 8c602071c2
5 changed files with 49 additions and 25 deletions

View 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;
}

View File

@ -683,20 +683,20 @@ 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']);
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)) {
Logger::notice('item parent was not found - ignoring item', ['thr-parent-id' => $item['thr-parent-id'], 'uid' => $item['uid']]);
@ -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;
}

View 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 {

View 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;

View 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 {