Merge remote-tracking branch 'upstream/develop' into push-pull

This commit is contained in:
Michael 2020-03-03 06:55:13 +00:00
commit 6f0d40c6c0
82 changed files with 1178 additions and 798 deletions

View file

@ -29,6 +29,7 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\APContact;
use Friendica\Model\Contact;
use Friendica\Model\Conversation;
use Friendica\Model\Event;
use Friendica\Model\Item;
use Friendica\Model\Mail;
@ -375,7 +376,7 @@ class Processor
Logger::warning('Unknown parent item.', ['uri' => $item['thr-parent']]);
return false;
}
if ($item_private && !$parent['private']) {
if ($item_private && ($parent['private'] == Item::PRIVATE)) {
Logger::warning('Item is private but the parent is not. Dropping.', ['item-uri' => $item['uri'], 'thr-parent' => $item['thr-parent']]);
return false;
}
@ -442,12 +443,26 @@ class Processor
}
$item['network'] = Protocol::ACTIVITYPUB;
$item['private'] = !in_array(0, $activity['receiver']);
$item['author-link'] = $activity['author'];
$item['author-id'] = Contact::getIdForURL($activity['author'], 0, true);
$item['owner-link'] = $activity['actor'];
$item['owner-id'] = Contact::getIdForURL($activity['actor'], 0, true);
if (in_array(0, $activity['receiver']) && !empty($activity['unlisted'])) {
$item['private'] = Item::UNLISTED;
} elseif (in_array(0, $activity['receiver'])) {
$item['private'] = Item::PUBLIC;
} else {
$item['private'] = Item::PRIVATE;
}
if (!empty($activity['raw'])) {
$item['source'] = $activity['raw'];
$item['protocol'] = Conversation::PARCEL_ACTIVITYPUB;
$item['conversation-href'] = $activity['context'] ?? '';
$item['conversation-uri'] = $activity['conversation'] ?? '';
}
$isForum = false;
if (!empty($activity['thread-completion'])) {
@ -490,6 +505,10 @@ class Processor
$stored = false;
foreach ($activity['receiver'] as $receiver) {
if ($receiver == -1) {
continue;
}
$item['uid'] = $receiver;
if ($isForum) {
@ -539,7 +558,7 @@ class Processor
}
// Store send a follow request for every reshare - but only when the item had been stored
if ($stored && !$item['private'] && ($item['gravity'] == GRAVITY_PARENT) && ($item['author-link'] != $item['owner-link'])) {
if ($stored && ($item['private'] != Item::PRIVATE) && ($item['gravity'] == GRAVITY_PARENT) && ($item['author-link'] != $item['owner-link'])) {
$author = APContact::getByURL($item['owner-link'], false);
// We send automatic follow requests for reshared messages. (We don't need though for forum posts)
if ($author['type'] != 'Group') {

View file

@ -28,7 +28,6 @@ use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Model\Contact;
use Friendica\Model\APContact;
use Friendica\Model\Conversation;
use Friendica\Model\Item;
use Friendica\Model\User;
use Friendica\Protocol\Activity;
@ -306,33 +305,6 @@ class Receiver
return 0;
}
/**
* Store the unprocessed data into the conversation table
* This has to be done outside the regular function,
* since we store everything - not only item posts.
*
* @param array $activity Array with activity data
* @param string $body The raw message
* @throws \Exception
*/
private static function storeConversation($activity, $body)
{
if (empty($body) || empty($activity['id'])) {
return;
}
$conversation = [
'protocol' => Conversation::PARCEL_ACTIVITYPUB,
'item-uri' => $activity['id'],
'reply-to-uri' => $activity['reply-to-id'] ?? '',
'conversation-href' => $activity['context'] ?? '',
'conversation-uri' => $activity['conversation'] ?? '',
'source' => $body,
'received' => DateTimeFormat::utcNow()];
DBA::insert('conversation', $conversation, true);
}
/**
* Processes the activity object
*
@ -383,9 +355,8 @@ class Receiver
return;
}
// Only store content related stuff - and no announces, since they possibly overwrite the original content
if (in_array($object_data['object_type'], self::CONTENT_TYPES) && ($type != 'as:Announce')) {
self::storeConversation($object_data, $body);
if (!empty($body)) {
$object_data['raw'] = $body;
}
// Internal flag for thread completion. See Processor.php
@ -509,14 +480,15 @@ class Receiver
/**
* Fetch the receiver list from an activity array
*
* @param array $activity
* @param string $actor
* @param array $tags
* @param array $activity
* @param string $actor
* @param array $tags
* @param boolean $fetch_unlisted
*
* @return array with receivers (user id)
* @throws \Exception
*/
private static function getReceivers($activity, $actor, $tags = [])
private static function getReceivers($activity, $actor, $tags = [], $fetch_unlisted = false)
{
$receivers = [];
@ -554,6 +526,11 @@ class Receiver
$receivers['uid:0'] = 0;
}
// Add receiver "-1" for unlisted posts
if ($fetch_unlisted && ($receiver == self::PUBLIC_COLLECTION) && ($element == 'as:cc')) {
$receivers['uid:-1'] = -1;
}
if (($receiver == self::PUBLIC_COLLECTION) && !empty($actor)) {
// This will most likely catch all OStatus connections to Mastodon
$condition = ['alias' => [$actor, Strings::normaliseLink($actor)], 'rel' => [Contact::SHARING, Contact::FRIEND]
@ -1025,7 +1002,9 @@ class Receiver
}
}
$object_data['receiver'] = self::getReceivers($object, $object_data['actor'], $object_data['tags']);
$object_data['receiver'] = self::getReceivers($object, $object_data['actor'], $object_data['tags'], true);
$object_data['unlisted'] = in_array(-1, $object_data['receiver']);
unset($object_data['receiver']['uid:-1']);
// Common object data:

View file

@ -173,7 +173,7 @@ class Transmitter
$public_contact = Contact::getIdForURL($owner['url'], 0, true);
$condition = ['uid' => 0, 'contact-id' => $public_contact, 'author-id' => $public_contact,
'private' => false, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT],
'private' => [Item::PUBLIC, Item::UNLISTED], 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT],
'deleted' => false, 'visible' => true, 'moderated' => false];
$count = DBA::count('item', $condition);
@ -264,7 +264,7 @@ class Transmitter
$data['name'] = $contact['name'];
$data['vcard:hasAddress'] = ['@type' => 'vcard:Home', 'vcard:country-name' => $profile['country-name'],
'vcard:region' => $profile['region'], 'vcard:locality' => $profile['locality']];
$data['summary'] = $contact['about'];
$data['summary'] = BBCode::convert($contact['about'], false);
$data['url'] = $contact['url'];
$data['manuallyApprovesFollowers'] = in_array($user['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP]);
$data['publicKey'] = ['id' => $contact['url'] . '#main-key',
@ -401,7 +401,7 @@ class Transmitter
$terms = Term::tagArrayFromItemId($item['id'], [Term::MENTION, Term::IMPLICIT_MENTION]);
if (!$item['private']) {
if ($item['private'] != Item::PRIVATE) {
// Directly mention the original author upon a quoted reshare.
// Else just ensure that the original author receives the reshare.
$announce = self::getAnnounceArray($item);
@ -413,7 +413,12 @@ class Transmitter
$data = array_merge($data, self::fetchPermissionBlockFromConversation($item));
$data['to'][] = ActivityPub::PUBLIC_COLLECTION;
// Check if the item is completely public or unlisted
if ($item['private'] == Item::PUBLIC) {
$data['to'][] = ActivityPub::PUBLIC_COLLECTION;
} else {
$data['cc'][] = ActivityPub::PUBLIC_COLLECTION;
}
foreach ($terms as $term) {
$profile = APContact::getByURL($term['url'], false);
@ -467,13 +472,13 @@ class Transmitter
$data['to'][] = $profile['url'];
} else {
$data['cc'][] = $profile['url'];
if (!$item['private'] && !empty($actor_profile['followers'])) {
if (($item['private'] != Item::PRIVATE) && $item['private'] && !empty($actor_profile['followers'])) {
$data['cc'][] = $actor_profile['followers'];
}
}
} else {
// Public thread parent post always are directed to the followers
if (!$item['private'] && !$forum_mode) {
if (($item['private'] != Item::PRIVATE) && !$forum_mode) {
$data['cc'][] = $actor_profile['followers'];
}
}