diff --git a/src/Model/Item.php b/src/Model/Item.php index 62f5c7148..03a62f584 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1712,8 +1712,7 @@ class Item $item['owner-id'] = ($item['owner-id'] ?? 0) ?: Contact::getIdForURL($item['owner-link'], 0, null, $default); $actor = ($item['gravity'] == GRAVITY_PARENT) ? $item['owner-id'] : $item['author-id']; - if (in_array($item['post-type'], [self::PT_ARTICLE, self::PT_COMMENT, self::PT_RELAY, self::PT_GLOBAL]) - && !$item['origin'] && ($item['uid'] != 0) && Contact::isSharing($actor, $item['uid'])) { + if (!$item['origin'] && ($item['uid'] != 0) && Contact::isSharing($actor, $item['uid'])) { $item['post-type'] = self::PT_FOLLOWER; } @@ -2038,8 +2037,7 @@ class Item } if ($author['contact-type'] != Contact::TYPE_COMMUNITY) { - if (!in_array($parent['post-type'], [self::PT_ARTICLE, self::PT_COMMENT, self::PT_STORED, self::PT_GLOBAL, self::PT_RELAY, self::PT_FETCHED]) - || Contact::isSharing($parent['owner-id'], $item['uid'])) { + if (Contact::isSharing($parent['owner-id'], $item['uid'])) { Logger::info('The resharer is no forum: quit', ['resharer' => $item['author-id'], 'owner' => $parent['owner-id'], 'author' => $parent['author-id'], 'uid' => $item['uid']]); return; } @@ -2382,6 +2380,7 @@ class Item unset($item['starred']); unset($item['postopts']); unset($item['inform']); + unset($item['post-type']); if ($item['uri'] == $item['parent-uri']) { $item['contact-id'] = $item['owner-id']; } else { @@ -2444,6 +2443,7 @@ class Item unset($item['starred']); unset($item['postopts']); unset($item['inform']); + unset($item['post-type']); $item['contact-id'] = Contact::getIdForURL($item['author-link']); $public_shadow = self::insert($item, false, true); diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 95eecabca..d2acdb740 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -488,6 +488,7 @@ class Processor } $stored = false; + ksort($activity['receiver']); foreach ($activity['receiver'] as $receiver) { if ($receiver == -1) { @@ -523,12 +524,10 @@ class Processor $item['post-type'] = Item::PT_ARTICLE; } - if (in_array($item['post-type'], [Item::PT_COMMENT, Item::PT_GLOBAL, Item::PT_ARTICLE])) { - if (!empty($activity['from-relay'])) { - $item['post-type'] = Item::PT_RELAY; - } elseif (!empty($activity['thread-completion'])) { - $item['post-type'] = Item::PT_FETCHED; - } + if (!empty($activity['from-relay'])) { + $item['post-type'] = Item::PT_RELAY; + } elseif (!empty($activity['thread-completion'])) { + $item['post-type'] = Item::PT_FETCHED; } if (!empty($activity['from-relay'])) { diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php index 00e6d5c31..ed0426550 100644 --- a/src/Protocol/ActivityPub/Receiver.php +++ b/src/Protocol/ActivityPub/Receiver.php @@ -282,14 +282,14 @@ class Receiver $receivers = $reception_types = []; foreach ($receiverdata as $key => $data) { $receivers[$key] = $data['uid']; - $reception_types[$data['uid']] = $data['type'] ?? 0; + $reception_types[$data['uid']] = $data['type'] ?? self::TARGET_UNKNOWN; } // When it is a delivery to a personal inbox we add that user to the receivers if (!empty($uid)) { - $additional = ['uid:' . $uid => $uid]; - $receivers = array_merge($receivers, $additional); - if (empty($reception_types[$uid]) || in_array($reception_types[$uid], [self::TARGET_UNKNOWN, self::TARGET_FOLLOWER, self::TARGET_ANSWER, self::TARGET_GLOBAL])) { + $additional = [$uid => $uid]; + $receivers = array_replace($receivers, $additional); + if (empty($activity['thread-completion']) && (empty($reception_types[$uid]) || in_array($reception_types[$uid], [self::TARGET_UNKNOWN, self::TARGET_FOLLOWER, self::TARGET_ANSWER, self::TARGET_GLOBAL]))) { $reception_types[$uid] = self::TARGET_BCC; } } else { @@ -372,8 +372,8 @@ class Receiver $object_data['type'] = $type; $object_data['actor'] = $actor; $object_data['item_receiver'] = $receivers; - $object_data['receiver'] = array_merge($object_data['receiver'] ?? [], $receivers); - $object_data['reception_type'] = array_merge($object_data['reception_type'] ?? [], $reception_types); + $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'])) { @@ -633,7 +633,7 @@ class Receiver if (!empty($reply)) { $parents = Item::select(['uid'], ['uri' => $reply]); while ($parent = Item::fetch($parents)) { - $receivers['uid:' . $parent['uid']] = ['uid' => $parent['uid'], 'type' => self::TARGET_ANSWER]; + $receivers[$parent['uid']] = ['uid' => $parent['uid'], 'type' => self::TARGET_ANSWER]; } } @@ -647,6 +647,9 @@ class Receiver $followers = ''; } + // We have to prevent false follower assumptions upon thread completions + $follower_target = empty($activity['thread-completion']) ? self::TARGET_FOLLOWER : self::TARGET_UNKNOWN; + foreach (['as:to', 'as:cc', 'as:bto', 'as:bcc'] as $element) { $receiver_list = JsonLD::fetchElementArray($activity, $element, '@id'); if (empty($receiver_list)) { @@ -655,17 +658,17 @@ class Receiver foreach ($receiver_list as $receiver) { if ($receiver == self::PUBLIC_COLLECTION) { - $receivers['uid:0'] = ['uid' => 0, 'type' => self::TARGET_GLOBAL]; + $receivers[0] = ['uid' => 0, 'type' => self::TARGET_GLOBAL]; } // Add receiver "-1" for unlisted posts if ($fetch_unlisted && ($receiver == self::PUBLIC_COLLECTION) && ($element == 'as:cc')) { - $receivers['uid:-1'] = ['uid' => -1, 'type' => self::TARGET_GLOBAL]; + $receivers[-1] = ['uid' => -1, 'type' => self::TARGET_GLOBAL]; } // Fetch the receivers for the public and the followers collection if (in_array($receiver, [$followers, self::PUBLIC_COLLECTION]) && !empty($actor)) { - $receivers = self::getReceiverForActor($actor, $tags, $receivers); + $receivers = self::getReceiverForActor($actor, $tags, $receivers, $follower_target); continue; } @@ -693,7 +696,7 @@ class Receiver } } - $type = $receivers['uid:' . $contact['uid']]['type'] ?? self::TARGET_UNKNOWN; + $type = $receivers[$contact['uid']]['type'] ?? self::TARGET_UNKNOWN; if (in_array($type, [self::TARGET_UNKNOWN, self::TARGET_FOLLOWER, self::TARGET_ANSWER, self::TARGET_GLOBAL])) { switch ($element) { case 'as:to': @@ -710,7 +713,7 @@ class Receiver break; } - $receivers['uid:' . $contact['uid']] = ['uid' => $contact['uid'], 'type' => $type]; + $receivers[$contact['uid']] = ['uid' => $contact['uid'], 'type' => $type]; } } } @@ -723,13 +726,15 @@ class Receiver /** * Fetch the receiver list of a given actor * - * @param string $actor - * @param array $tags + * @param string $actor + * @param array $tags + * @param array $receivers + * @param integer $target_type * * @return array with receivers (user id) * @throws \Exception */ - private static function getReceiverForActor($actor, $tags, $receivers) + private static function getReceiverForActor($actor, $tags, $receivers, $target_type) { $basecondition = ['rel' => [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER], 'network' => Protocol::FEDERATED, 'archive' => false, 'pending' => false]; @@ -737,8 +742,8 @@ class Receiver $condition = DBA::mergeConditions($basecondition, ["`nurl` = ? AND `uid` != ?", Strings::normaliseLink($actor), 0]); $contacts = DBA::select('contact', ['uid', 'rel'], $condition); while ($contact = DBA::fetch($contacts)) { - if (empty($receivers['uid:' . $contact['uid']]) && self::isValidReceiverForActor($contact, $tags)) { - $receivers['uid:' . $contact['uid']] = ['uid' => $contact['uid'], 'type' => self::TARGET_FOLLOWER]; + if (empty($receivers[$contact['uid']]) && self::isValidReceiverForActor($contact, $tags)) { + $receivers[$contact['uid']] = ['uid' => $contact['uid'], 'type' => $target_type]; } } DBA::close($contacts); @@ -747,8 +752,8 @@ class Receiver $condition = DBA::mergeConditions($basecondition, ["`alias` IN (?, ?) AND `uid` != ?", Strings::normaliseLink($actor), $actor, 0]); $contacts = DBA::select('contact', ['uid', 'rel'], $condition); while ($contact = DBA::fetch($contacts)) { - if (empty($receivers['uid:' . $contact['uid']]) && self::isValidReceiverForActor($contact, $tags)) { - $receivers['uid:' . $contact['uid']] = ['uid' => $contact['uid'], 'type' => self::TARGET_FOLLOWER]; + if (empty($receivers[$contact['uid']]) && self::isValidReceiverForActor($contact, $tags)) { + $receivers[$contact['uid']] = ['uid' => $contact['uid'], 'type' => $target_type]; } } DBA::close($contacts); @@ -1346,7 +1351,8 @@ class Receiver $object_data['reception_type'] = $reception_types; $object_data['unlisted'] = in_array(-1, $object_data['receiver']); - unset($object_data['receiver']['uid:-1']); + unset($object_data['receiver'][-1]); + unset($object_data['reception_type'][-1]); // Common object data: