Bookwyrm posts now work
This commit is contained in:
parent
7eb410bed7
commit
8c602071c2
|
@ -539,6 +539,13 @@ class APContact
|
||||||
HTTPSignature::setInboxStatus($url, true, $shared);
|
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
|
public static function isRelay(array $apcontact): bool
|
||||||
{
|
{
|
||||||
if ($apcontact['nick'] != 'relay') {
|
if ($apcontact['nick'] != 'relay') {
|
||||||
|
@ -549,7 +556,7 @@ class APContact
|
||||||
return true;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -683,19 +683,19 @@ class Item
|
||||||
'uri-id', 'parent-uri-id',
|
'uri-id', 'parent-uri-id',
|
||||||
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
|
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
|
||||||
'wall', 'private', 'origin', 'author-id'];
|
'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]];
|
$params = ['order' => ['id' => false]];
|
||||||
$parent = Post::selectFirst($fields, $condition, $params);
|
$parent = Post::selectFirst($fields, $condition, $params);
|
||||||
|
|
||||||
if (!DBA::isResult($parent) && ($item['thr-parent-id'] != $item['parent-uri-id'])) {
|
if (!DBA::isResult($parent) && Post::exists(['uri-id' => [$item['thr-parent-id'], $item['parent-uri-id']], 'uid' => 0])) {
|
||||||
$condition = ['uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']];
|
|
||||||
$parent = Post::selectFirst($fields, $condition, $params);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!DBA::isResult($parent) && $item['origin']) {
|
|
||||||
$stored = Item::storeForUserByUriId($item['thr-parent-id'], $item['uid']);
|
$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]);
|
if (!$stored && ($item['thr-parent-id'] != $item['parent-uri-id'])) {
|
||||||
$parent = Post::selectFirst($fields, $condition, $params);
|
$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)) {
|
if (!DBA::isResult($parent)) {
|
||||||
|
@ -908,7 +908,7 @@ class Item
|
||||||
$item['contact-id'] = self::contactId($item);
|
$item['contact-id'] = self::contactId($item);
|
||||||
|
|
||||||
if (!empty($item['direction']) && in_array($item['direction'], [Conversation::PUSH, Conversation::RELAY]) &&
|
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]);
|
Logger::info('Item is too old', ['item' => $item]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -299,7 +299,7 @@ class Processor
|
||||||
if (empty($activity['directmessage']) && ($activity['id'] != $activity['reply-to-id']) && !Post::exists(['uri' => $activity['reply-to-id']])) {
|
if (empty($activity['directmessage']) && ($activity['id'] != $activity['reply-to-id']) && !Post::exists(['uri' => $activity['reply-to-id']])) {
|
||||||
$recursion_depth = $activity['recursion-depth'] ?? 0;
|
$recursion_depth = $activity['recursion-depth'] ?? 0;
|
||||||
Logger::notice('Parent not found. Try to refetch it.', ['parent' => $activity['reply-to-id'], 'recursion-depth' => $recursion_depth]);
|
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);
|
$result = self::fetchMissingActivity($activity['reply-to-id'], $activity, '', Receiver::COMPLETION_AUTO);
|
||||||
$fetch_by_worker = empty($result);
|
$fetch_by_worker = empty($result);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -437,17 +437,18 @@ class Receiver
|
||||||
$object_data['receiver'] = array_replace($object_data['receiver'] ?? [], $receivers);
|
$object_data['receiver'] = array_replace($object_data['receiver'] ?? [], $receivers);
|
||||||
$object_data['reception_type'] = array_replace($object_data['reception_type'] ?? [], $reception_types);
|
$object_data['reception_type'] = array_replace($object_data['reception_type'] ?? [], $reception_types);
|
||||||
|
|
||||||
$author = $object_data['author'] ?? $actor;
|
// This check here interferes with Hubzilla posts where the author host differs from the host the post was created
|
||||||
if (!empty($author) && !empty($object_data['id'])) {
|
// $author = $object_data['author'] ?? $actor;
|
||||||
$author_host = parse_url($author, PHP_URL_HOST);
|
// if (!empty($author) && !empty($object_data['id'])) {
|
||||||
$id_host = parse_url($object_data['id'], PHP_URL_HOST);
|
// $author_host = parse_url($author, PHP_URL_HOST);
|
||||||
if ($author_host == $id_host) {
|
// $id_host = parse_url($object_data['id'], PHP_URL_HOST);
|
||||||
Logger::info('Valid hosts', ['type' => $type, 'host' => $id_host]);
|
// if ($author_host == $id_host) {
|
||||||
} else {
|
// Logger::info('Valid hosts', ['type' => $type, 'host' => $id_host]);
|
||||||
Logger::notice('Differing hosts on author and id', ['type' => $type, 'author' => $author_host, 'id' => $id_host]);
|
// } else {
|
||||||
$trust_source = false;
|
// 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']);
|
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'] ?? [];
|
$activity = $object_data['object_activity'] ?? [];
|
||||||
|
|
||||||
|
@ -627,7 +637,7 @@ class Receiver
|
||||||
|
|
||||||
$item = ActivityPub\Processor::createItem($object_data);
|
$item = ActivityPub\Processor::createItem($object_data);
|
||||||
if (empty($item)) {
|
if (empty($item)) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$item['post-reason'] = Item::PR_ANNOUNCEMENT;
|
$item['post-reason'] = Item::PR_ANNOUNCEMENT;
|
||||||
|
|
|
@ -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));
|
$jsonobj = json_decode(json_encode($json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue