Issue 9264: post types should now work

This commit is contained in:
Michael 2020-09-25 06:47:07 +00:00
parent e0b0ca96d1
commit 9552473db5
3 changed files with 35 additions and 30 deletions

View File

@ -1712,8 +1712,7 @@ class Item
$item['owner-id'] = ($item['owner-id'] ?? 0) ?: Contact::getIdForURL($item['owner-link'], 0, null, $default); $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']; $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]) if (!$item['origin'] && ($item['uid'] != 0) && Contact::isSharing($actor, $item['uid'])) {
&& !$item['origin'] && ($item['uid'] != 0) && Contact::isSharing($actor, $item['uid'])) {
$item['post-type'] = self::PT_FOLLOWER; $item['post-type'] = self::PT_FOLLOWER;
} }
@ -2038,8 +2037,7 @@ class Item
} }
if ($author['contact-type'] != Contact::TYPE_COMMUNITY) { 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]) if (Contact::isSharing($parent['owner-id'], $item['uid'])) {
|| 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']]); Logger::info('The resharer is no forum: quit', ['resharer' => $item['author-id'], 'owner' => $parent['owner-id'], 'author' => $parent['author-id'], 'uid' => $item['uid']]);
return; return;
} }
@ -2382,6 +2380,7 @@ class Item
unset($item['starred']); unset($item['starred']);
unset($item['postopts']); unset($item['postopts']);
unset($item['inform']); unset($item['inform']);
unset($item['post-type']);
if ($item['uri'] == $item['parent-uri']) { if ($item['uri'] == $item['parent-uri']) {
$item['contact-id'] = $item['owner-id']; $item['contact-id'] = $item['owner-id'];
} else { } else {
@ -2444,6 +2443,7 @@ class Item
unset($item['starred']); unset($item['starred']);
unset($item['postopts']); unset($item['postopts']);
unset($item['inform']); unset($item['inform']);
unset($item['post-type']);
$item['contact-id'] = Contact::getIdForURL($item['author-link']); $item['contact-id'] = Contact::getIdForURL($item['author-link']);
$public_shadow = self::insert($item, false, true); $public_shadow = self::insert($item, false, true);

View File

@ -488,6 +488,7 @@ class Processor
} }
$stored = false; $stored = false;
ksort($activity['receiver']);
foreach ($activity['receiver'] as $receiver) { foreach ($activity['receiver'] as $receiver) {
if ($receiver == -1) { if ($receiver == -1) {
@ -523,12 +524,10 @@ class Processor
$item['post-type'] = Item::PT_ARTICLE; $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'])) {
if (!empty($activity['from-relay'])) { $item['post-type'] = Item::PT_RELAY;
$item['post-type'] = Item::PT_RELAY; } elseif (!empty($activity['thread-completion'])) {
} elseif (!empty($activity['thread-completion'])) { $item['post-type'] = Item::PT_FETCHED;
$item['post-type'] = Item::PT_FETCHED;
}
} }
if (!empty($activity['from-relay'])) { if (!empty($activity['from-relay'])) {

View File

@ -282,14 +282,14 @@ class Receiver
$receivers = $reception_types = []; $receivers = $reception_types = [];
foreach ($receiverdata as $key => $data) { foreach ($receiverdata as $key => $data) {
$receivers[$key] = $data['uid']; $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 // When it is a delivery to a personal inbox we add that user to the receivers
if (!empty($uid)) { if (!empty($uid)) {
$additional = ['uid:' . $uid => $uid]; $additional = [$uid => $uid];
$receivers = array_merge($receivers, $additional); $receivers = array_replace($receivers, $additional);
if (empty($reception_types[$uid]) || in_array($reception_types[$uid], [self::TARGET_UNKNOWN, self::TARGET_FOLLOWER, self::TARGET_ANSWER, self::TARGET_GLOBAL])) { 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; $reception_types[$uid] = self::TARGET_BCC;
} }
} else { } else {
@ -372,8 +372,8 @@ class Receiver
$object_data['type'] = $type; $object_data['type'] = $type;
$object_data['actor'] = $actor; $object_data['actor'] = $actor;
$object_data['item_receiver'] = $receivers; $object_data['item_receiver'] = $receivers;
$object_data['receiver'] = array_merge($object_data['receiver'] ?? [], $receivers); $object_data['receiver'] = array_replace($object_data['receiver'] ?? [], $receivers);
$object_data['reception_type'] = array_merge($object_data['reception_type'] ?? [], $reception_types); $object_data['reception_type'] = array_replace($object_data['reception_type'] ?? [], $reception_types);
$author = $object_data['author'] ?? $actor; $author = $object_data['author'] ?? $actor;
if (!empty($author) && !empty($object_data['id'])) { if (!empty($author) && !empty($object_data['id'])) {
@ -633,7 +633,7 @@ class Receiver
if (!empty($reply)) { if (!empty($reply)) {
$parents = Item::select(['uid'], ['uri' => $reply]); $parents = Item::select(['uid'], ['uri' => $reply]);
while ($parent = Item::fetch($parents)) { 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 = ''; $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) { foreach (['as:to', 'as:cc', 'as:bto', 'as:bcc'] as $element) {
$receiver_list = JsonLD::fetchElementArray($activity, $element, '@id'); $receiver_list = JsonLD::fetchElementArray($activity, $element, '@id');
if (empty($receiver_list)) { if (empty($receiver_list)) {
@ -655,17 +658,17 @@ class Receiver
foreach ($receiver_list as $receiver) { foreach ($receiver_list as $receiver) {
if ($receiver == self::PUBLIC_COLLECTION) { 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 // Add receiver "-1" for unlisted posts
if ($fetch_unlisted && ($receiver == self::PUBLIC_COLLECTION) && ($element == 'as:cc')) { 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 // Fetch the receivers for the public and the followers collection
if (in_array($receiver, [$followers, self::PUBLIC_COLLECTION]) && !empty($actor)) { 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; 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])) { if (in_array($type, [self::TARGET_UNKNOWN, self::TARGET_FOLLOWER, self::TARGET_ANSWER, self::TARGET_GLOBAL])) {
switch ($element) { switch ($element) {
case 'as:to': case 'as:to':
@ -710,7 +713,7 @@ class Receiver
break; 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 * Fetch the receiver list of a given actor
* *
* @param string $actor * @param string $actor
* @param array $tags * @param array $tags
* @param array $receivers
* @param integer $target_type
* *
* @return array with receivers (user id) * @return array with receivers (user id)
* @throws \Exception * @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], $basecondition = ['rel' => [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER],
'network' => Protocol::FEDERATED, 'archive' => false, 'pending' => false]; 'network' => Protocol::FEDERATED, 'archive' => false, 'pending' => false];
@ -737,8 +742,8 @@ class Receiver
$condition = DBA::mergeConditions($basecondition, ["`nurl` = ? AND `uid` != ?", Strings::normaliseLink($actor), 0]); $condition = DBA::mergeConditions($basecondition, ["`nurl` = ? AND `uid` != ?", Strings::normaliseLink($actor), 0]);
$contacts = DBA::select('contact', ['uid', 'rel'], $condition); $contacts = DBA::select('contact', ['uid', 'rel'], $condition);
while ($contact = DBA::fetch($contacts)) { while ($contact = DBA::fetch($contacts)) {
if (empty($receivers['uid:' . $contact['uid']]) && self::isValidReceiverForActor($contact, $tags)) { if (empty($receivers[$contact['uid']]) && self::isValidReceiverForActor($contact, $tags)) {
$receivers['uid:' . $contact['uid']] = ['uid' => $contact['uid'], 'type' => self::TARGET_FOLLOWER]; $receivers[$contact['uid']] = ['uid' => $contact['uid'], 'type' => $target_type];
} }
} }
DBA::close($contacts); DBA::close($contacts);
@ -747,8 +752,8 @@ class Receiver
$condition = DBA::mergeConditions($basecondition, ["`alias` IN (?, ?) AND `uid` != ?", Strings::normaliseLink($actor), $actor, 0]); $condition = DBA::mergeConditions($basecondition, ["`alias` IN (?, ?) AND `uid` != ?", Strings::normaliseLink($actor), $actor, 0]);
$contacts = DBA::select('contact', ['uid', 'rel'], $condition); $contacts = DBA::select('contact', ['uid', 'rel'], $condition);
while ($contact = DBA::fetch($contacts)) { while ($contact = DBA::fetch($contacts)) {
if (empty($receivers['uid:' . $contact['uid']]) && self::isValidReceiverForActor($contact, $tags)) { if (empty($receivers[$contact['uid']]) && self::isValidReceiverForActor($contact, $tags)) {
$receivers['uid:' . $contact['uid']] = ['uid' => $contact['uid'], 'type' => self::TARGET_FOLLOWER]; $receivers[$contact['uid']] = ['uid' => $contact['uid'], 'type' => $target_type];
} }
} }
DBA::close($contacts); DBA::close($contacts);
@ -1346,7 +1351,8 @@ class Receiver
$object_data['reception_type'] = $reception_types; $object_data['reception_type'] = $reception_types;
$object_data['unlisted'] = in_array(-1, $object_data['receiver']); $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: // Common object data: