collections - testing activitypub cont.

This commit is contained in:
Mike Macgirvin 2024-01-27 07:40:25 +11:00
parent e60ee35905
commit 69411bab64

View file

@ -3897,6 +3897,7 @@ class Activity
}
$allowed = false;
$relay = false;
$reason = ['init'];
$isMail = (bool) (intval($item['item_private']) === 2);
if ($is_child_node) {
@ -3923,6 +3924,8 @@ class Activity
if ($parent_item && $parent_item['item_wall']) {
// set the owner to the owner of the parent
$item['owner_xchan'] = $parent_item['owner_xchan'];
// This check may be redundant at this point.
$relay = $channel['channel_hash'] === $item['owner_xchan'];
if ($parent_item['obj_type'] === 'Question') {
if ($item['obj_type'] === 'Note' && $item['title'] && (!$item['content'])) {
@ -3961,7 +3964,7 @@ class Activity
return;
}
}
$allowed = self::comment_allowed($channel, $item, $parent_item);
if ($allowed) {
@ -4025,9 +4028,7 @@ class Activity
}
}
$relay = $channel['channel_hash'] === $item['owner_xchan'];
if (str_contains($item['tgt_type'], 'Collection') && !$relay && !$isCollectionOperation) {
if ($parent_item && str_contains($parent_item['tgt_type'], 'Collection') && !$relay && !$isCollectionOperation) {
logger('not a collection activity');
return;
}
@ -4386,12 +4387,14 @@ class Activity
{
logger('fetching parents');
$conversation = [];
$seen_mids = [];
$current_item = $item;
while ($current_item['parent_mid'] !== $current_item['mid']) {
$isCollectionOperation = false;
// recursion breaker
if (in_array($current_item['parent_mid'], $seen_mids)) {
break;
@ -4410,7 +4413,19 @@ class Activity
// This is a relayed/forwarded Activity (as opposed to a shared/boosted object)
// Reparse the encapsulated Activity and use that instead
logger('relayed activity', LOGGER_DEBUG);
$activity = new ActivityStreams($activity->obj, null, true);
$rawActivity = json_decode($activity->raw, true);
$activity = new ActivityStreams($rawActivity['object'], null, true);
}
if (in_array($activity->type, ['Add', 'Remove'])
&& is_array($activity->obj)
&& array_key_exists('object', $activity->obj)
&& array_key_exists('actor', $activity->obj)
&& !empty($activity->tgt)) {
logger('relayed collection operation', LOGGER_DEBUG);
$isCollectionOperation = true;
$rawActivity = json_decode($activity->raw, true);
$activity = new ActivityStreams($rawActivity['object'], portable_id: $env['sender']);
}
logger($activity->debug(), LOGGER_DATA);
@ -4465,7 +4480,7 @@ class Activity
if ($conversation && $conversation[0]['item']['mid'] === $conversation[0]['item']['parent_mid']) {
foreach ($conversation as $post) {
if ($post['activity']->is_valid()) {
self::store($channel, $observer_hash, $post['activity'], $post['item'], false);
self::store($channel, $observer_hash, $post['activity'], $post['item'], false, isCollectionOperation: $isCollectionOperation);
}
}
return true;