/**
* Prepares data for a message
*
- * @param array $activity Activity array
+ * @param array $activity Activity array
+ * @param bool $fetch_parents
+ *
* @return array Internal item
+ *
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public static function createItem(array $activity): array
+ public static function createItem(array $activity, bool $fetch_parents = true): array
{
$item = [];
$item['verb'] = Activity::POST;
return [];
}
- if (empty($activity['directmessage']) && ($activity['id'] != $activity['reply-to-id']) && !Post::exists(['uri' => $activity['reply-to-id']])) {
+ if ($fetch_parents && empty($activity['directmessage']) && ($activity['id'] != $activity['reply-to-id']) && !Post::exists(['uri' => $activity['reply-to-id']])) {
$result = self::fetchParent($activity);
if (!empty($result)) {
if (($item['thr-parent'] != $result) && Post::exists(['uri' => $result])) {
* Process the activity with the given id
*
* @param integer $id
+ * @param bool $fetch_parents
*
* @return bool
*/
- public static function process(int $id): bool
+ public static function process(int $id, bool $fetch_parents = true): bool
{
$entry = DBA::selectFirst('inbox-entry', [], ['id' => $id]);
if (empty($entry)) {
}
DBA::close($receivers);
- if (!Receiver::routeActivities($activity, $type, $push)) {
+ if (!Receiver::routeActivities($activity, $type, $push, $fetch_parents)) {
self::remove($activity);
}
continue;
}
Logger::debug('Process leftover entry', $entry);
- self::process($entry['id']);
+ self::process($entry['id'], false);
}
DBA::close($entries);
}
$entries = DBA::select('inbox-entry', ['id'], ["`in-reply-to-id` = ? AND `object-id` != ?", $uri, $uri]);
while ($entry = DBA::fetch($entries)) {
$count += 1;
- self::process($entry['id']);
+ self::process($entry['id'], false);
}
DBA::close($entries);
return $count;
/**
* Route activities
*
- * @param array $object_data
- * @param string $type
- * @param boolean $push
+ * @param array $object_data
+ * @param string $type
+ * @param bool $push
+ * @param bool $fetch_parents
*
* @return boolean Could the activity be routed?
*/
- public static function routeActivities(array $object_data, string $type, bool $push): bool
+ public static function routeActivities(array $object_data, string $type, bool $push, bool $fetch_parents = true): bool
{
$activity = $object_data['object_activity'] ?? [];
switch ($type) {
case 'as:Create':
if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
- $item = ActivityPub\Processor::createItem($object_data);
+ $item = ActivityPub\Processor::createItem($object_data, $fetch_parents);
ActivityPub\Processor::postItem($object_data, $item);
} elseif (in_array($object_data['object_type'], ['pt:CacheFile'])) {
// Unhandled Peertube activity
case 'as:Invite':
if (in_array($object_data['object_type'], ['as:Event'])) {
- $item = ActivityPub\Processor::createItem($object_data);
+ $item = ActivityPub\Processor::createItem($object_data, $fetch_parents);
ActivityPub\Processor::postItem($object_data, $item);
} else {
return false;
$object_data['thread-completion'] = Contact::getIdForURL($actor);
$object_data['completion-mode'] = self::COMPLETION_ANNOUCE;
- $item = ActivityPub\Processor::createItem($object_data);
+ $item = ActivityPub\Processor::createItem($object_data, $fetch_parents);
if (empty($item)) {
return false;
}