Don't always fetch parent posts
This commit is contained in:
parent
23ef4a99bb
commit
3463e34693
|
@ -266,11 +266,14 @@ class Processor
|
||||||
* Prepares data for a message
|
* Prepares data for a message
|
||||||
*
|
*
|
||||||
* @param array $activity Activity array
|
* @param array $activity Activity array
|
||||||
|
* @param bool $fetch_parents
|
||||||
|
*
|
||||||
* @return array Internal item
|
* @return array Internal item
|
||||||
|
*
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
public static function createItem(array $activity): array
|
public static function createItem(array $activity, bool $fetch_parents = true): array
|
||||||
{
|
{
|
||||||
$item = [];
|
$item = [];
|
||||||
$item['verb'] = Activity::POST;
|
$item['verb'] = Activity::POST;
|
||||||
|
@ -305,7 +308,7 @@ class Processor
|
||||||
return [];
|
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);
|
$result = self::fetchParent($activity);
|
||||||
if (!empty($result)) {
|
if (!empty($result)) {
|
||||||
if (($item['thr-parent'] != $result) && Post::exists(['uri' => $result])) {
|
if (($item['thr-parent'] != $result) && Post::exists(['uri' => $result])) {
|
||||||
|
|
|
@ -175,10 +175,11 @@ class Queue
|
||||||
* Process the activity with the given id
|
* Process the activity with the given id
|
||||||
*
|
*
|
||||||
* @param integer $id
|
* @param integer $id
|
||||||
|
* @param bool $fetch_parents
|
||||||
*
|
*
|
||||||
* @return bool
|
* @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]);
|
$entry = DBA::selectFirst('inbox-entry', [], ['id' => $id]);
|
||||||
if (empty($entry)) {
|
if (empty($entry)) {
|
||||||
|
@ -215,7 +216,7 @@ class Queue
|
||||||
}
|
}
|
||||||
DBA::close($receivers);
|
DBA::close($receivers);
|
||||||
|
|
||||||
if (!Receiver::routeActivities($activity, $type, $push)) {
|
if (!Receiver::routeActivities($activity, $type, $push, $fetch_parents)) {
|
||||||
self::remove($activity);
|
self::remove($activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +237,7 @@ class Queue
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Logger::debug('Process leftover entry', $entry);
|
Logger::debug('Process leftover entry', $entry);
|
||||||
self::process($entry['id']);
|
self::process($entry['id'], false);
|
||||||
}
|
}
|
||||||
DBA::close($entries);
|
DBA::close($entries);
|
||||||
}
|
}
|
||||||
|
@ -272,7 +273,7 @@ class Queue
|
||||||
$entries = DBA::select('inbox-entry', ['id'], ["`in-reply-to-id` = ? AND `object-id` != ?", $uri, $uri]);
|
$entries = DBA::select('inbox-entry', ['id'], ["`in-reply-to-id` = ? AND `object-id` != ?", $uri, $uri]);
|
||||||
while ($entry = DBA::fetch($entries)) {
|
while ($entry = DBA::fetch($entries)) {
|
||||||
$count += 1;
|
$count += 1;
|
||||||
self::process($entry['id']);
|
self::process($entry['id'], false);
|
||||||
}
|
}
|
||||||
DBA::close($entries);
|
DBA::close($entries);
|
||||||
return $count;
|
return $count;
|
||||||
|
|
|
@ -629,18 +629,19 @@ class Receiver
|
||||||
*
|
*
|
||||||
* @param array $object_data
|
* @param array $object_data
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param boolean $push
|
* @param bool $push
|
||||||
|
* @param bool $fetch_parents
|
||||||
*
|
*
|
||||||
* @return boolean Could the activity be routed?
|
* @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'] ?? [];
|
$activity = $object_data['object_activity'] ?? [];
|
||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'as:Create':
|
case 'as:Create':
|
||||||
if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
|
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);
|
ActivityPub\Processor::postItem($object_data, $item);
|
||||||
} elseif (in_array($object_data['object_type'], ['pt:CacheFile'])) {
|
} elseif (in_array($object_data['object_type'], ['pt:CacheFile'])) {
|
||||||
// Unhandled Peertube activity
|
// Unhandled Peertube activity
|
||||||
|
@ -652,7 +653,7 @@ class Receiver
|
||||||
|
|
||||||
case 'as:Invite':
|
case 'as:Invite':
|
||||||
if (in_array($object_data['object_type'], ['as:Event'])) {
|
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);
|
ActivityPub\Processor::postItem($object_data, $item);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -678,7 +679,7 @@ class Receiver
|
||||||
$object_data['thread-completion'] = Contact::getIdForURL($actor);
|
$object_data['thread-completion'] = Contact::getIdForURL($actor);
|
||||||
$object_data['completion-mode'] = self::COMPLETION_ANNOUCE;
|
$object_data['completion-mode'] = self::COMPLETION_ANNOUCE;
|
||||||
|
|
||||||
$item = ActivityPub\Processor::createItem($object_data);
|
$item = ActivityPub\Processor::createItem($object_data, $fetch_parents);
|
||||||
if (empty($item)) {
|
if (empty($item)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user