$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;
}
}
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;
}
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 {
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);
$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 {
$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'])) {
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];
}
}
$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)) {
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;
}
}
}
- $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':
break;
}
- $receivers['uid:' . $contact['uid']] = ['uid' => $contact['uid'], 'type' => $type];
+ $receivers[$contact['uid']] = ['uid' => $contact['uid'], 'type' => $type];
}
}
}
/**
* 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];
$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);
$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);
$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: