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

@ -769,6 +769,9 @@ function conversation_fetch_comments($thread_items, $pinned) {
case Item::PT_STORED:
$row['direction'] = ['direction' => 8, 'title' => DI::l10n()->t('Stored')];
break;
case Item::PT_GLOBAL:
$row['direction'] = ['direction' => 9, 'title' => DI::l10n()->t('Global')];
break;
default:
if ($row['uid'] == 0) {
$row['direction'] = ['direction' => 9, 'title' => DI::l10n()->t('Global')];

View file

@ -65,6 +65,7 @@ class Item
const PT_ANNOUNCEMENT = 70;
const PT_COMMENT = 71;
const PT_STORED = 72;
const PT_GLOBAL = 73;
const PT_PERSONAL_NOTE = 128;
// Field list that is used to display the items
@ -1700,7 +1701,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 (!$item['origin'] && in_array($item['post-type'], [self::PT_ARTICLE, self::PT_COMMENT]) && Contact::isSharing($actor, $item['uid'])) {
if (!$item['origin'] && in_array($item['post-type'], [self::PT_ARTICLE, self::PT_COMMENT, self::PT_GLOBAL]) && Contact::isSharing($actor, $item['uid'])) {
$item['post-type'] = self::PT_FOLLOWER;
}

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;

View file

@ -1736,7 +1736,7 @@ class Diaspora
$datarray["owner-id"] = Contact::getIdForURL($contact["url"], 0);
// Will be overwritten for sharing accounts in Item::insert
$datarray['post-type'] = Item::PT_COMMENT;
$datarray['post-type'] = ($datarray["uid"] == 0) ? Item::PT_GLOBAL : Item::PT_COMMENT;
$datarray["guid"] = $guid;
$datarray["uri"] = self::getUriFromGuid($author, $guid);
@ -2865,6 +2865,10 @@ class Diaspora
$datarray["protocol"] = Conversation::PARCEL_DIASPORA;
$datarray["source"] = $xml;
if ($datarray["uid"] == 0) {
$datarray["post-type"] = Item::PT_GLOBAL;
}
$datarray["body"] = self::replacePeopleGuid($body, $contact["url"]);
self::storeMentions($datarray['uri-id'], $text);