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') {
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;
}
'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)) {
$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;
}
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 {
$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']);
}
}
- 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'] ?? [];
$item = ActivityPub\Processor::createItem($object_data);
if (empty($item)) {
- return;
+ return false;
}
$item['post-reason'] = Item::PR_ANNOUNCEMENT;
}
}
+ // 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 {