We now set the "global" direction

This commit is contained in:
Michael 2020-09-14 17:48:57 +00:00
parent cade34cd2d
commit 08fa5f0c19
5 changed files with 18 additions and 41 deletions

View file

@ -26,7 +26,6 @@ use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\APContact;
@ -207,9 +206,6 @@ class Processor
} else {
$item['gravity'] = GRAVITY_COMMENT;
$item['object-type'] = Activity\ObjectType::COMMENT;
// Ensure that the comment reaches all receivers of the referring post
$activity['receiver'] = self::addReceivers($activity);
}
if (empty($activity['directmessage']) && ($activity['id'] != $activity['reply-to-id']) && !Item::exists(['uri' => $activity['reply-to-id']])) {
@ -331,35 +327,6 @@ class Processor
}
}
/**
* Add users to the receiver list of the given public activity.
* This is used to ensure that the activity will be stored in every thread.
*
* @param array $activity Activity array
* @return array Modified receiver list
*/
private static function addReceivers(array $activity)
{
if (!in_array(0, $activity['receiver'])) {
// Private activities will not be modified
return $activity['receiver'];
}
// Add all owners of the referring item to the receivers
$original = $receivers = $activity['receiver'];
$items = Item::select(['uid'], ['uri' => $activity['object_id']]);
while ($item = DBA::fetch($items)) {
$receivers['uid:' . $item['uid']] = $item['uid'];
}
DBA::close($items);
if (count($original) != count($receivers)) {
Logger::info('Improved data', ['id' => $activity['id'], 'object' => $activity['object_id'], 'original' => $original, 'improved' => $receivers, 'callstack' => System::callstack()]);
}
return $receivers;
}
/**
* Prepare the item array for an activity
*
@ -378,8 +345,6 @@ class Processor
$item['diaspora_signed_text'] = $activity['diaspora:like'] ?? '';
$activity['receiver'] = self::addReceivers($activity);
self::postItem($activity, $item);
}
@ -548,6 +513,9 @@ class Processor
case Receiver::TARGET_ANSWER:
$item['post-type'] = Item::PT_COMMENT;
break;
case Receiver::TARGET_GLOBAL:
$item['post-type'] = Item::PT_GLOBAL;
break;
default:
$item['post-type'] = Item::PT_ARTICLE;
}

View file

@ -65,6 +65,7 @@ class Receiver
const TARGET_BCC = 4;
const TARGET_FOLLOWER = 5;
const TARGET_ANSWER = 6;
const TARGET_GLOBAL = 7;
/**
* Checks if the web request is done for the AP protocol
@ -234,7 +235,7 @@ class Receiver
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])) {
if (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 {
@ -590,12 +591,12 @@ class Receiver
foreach ($receiver_list as $receiver) {
if ($receiver == self::PUBLIC_COLLECTION) {
$receivers['uid:0'] = ['uid' => 0, 'type' => self::TARGET_UNKNOWN];
$receivers['uid: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_UNKNOWN];
$receivers['uid:-1'] = ['uid' => -1, 'type' => self::TARGET_GLOBAL];
}
// Fetch the receivers for the public and the followers collection
@ -629,7 +630,7 @@ class Receiver
}
$type = $receivers['uid:' . $contact['uid']]['type'] ?? self::TARGET_UNKNOWN;
if (in_array($type, [self::TARGET_UNKNOWN, self::TARGET_FOLLOWER, self::TARGET_ANSWER])) {
if (in_array($type, [self::TARGET_UNKNOWN, self::TARGET_FOLLOWER, self::TARGET_ANSWER, self::TARGET_GLOBAL])) {
switch ($element) {
case 'as:to':
$type = self::TARGET_TO;