AP Improvements for forums

This commit is contained in:
Michael 2020-08-09 18:42:25 +00:00
parent e733055485
commit bf7128b4b2
6 changed files with 86 additions and 56 deletions

View file

@ -454,7 +454,9 @@ class Transmitter
if ($item['gravity'] != GRAVITY_PARENT) {
// Comments to forums are directed to the forum
// But comments to forums aren't directed to the followers collection
if ($profile['type'] == 'Group') {
// This rule is only valid when the actor isn't the forum.
// The forum needs to transmit their content to their followers.
if (($profile['type'] == 'Group') && ($profile['url'] != $actor_profile['url'])) {
$data['to'][] = $profile['url'];
} else {
$data['cc'][] = $profile['url'];
@ -627,6 +629,8 @@ class Transmitter
$item_profile = APContact::getByURL($item['owner-link'], false);
}
$profile_uid = User::getIdForURL($item_profile['url']);
foreach (['to', 'cc', 'bto', 'bcc'] as $element) {
if (empty($permissions[$element])) {
continue;
@ -639,7 +643,7 @@ class Transmitter
continue;
}
if ($item_profile && $receiver == $item_profile['followers']) {
if ($item_profile && ($receiver == $item_profile['followers']) && ($uid == $profile_uid)) {
$inboxes = array_merge($inboxes, self::fetchTargetInboxesforUser($uid, $personal));
} else {
if (Contact::isLocal($receiver)) {
@ -807,6 +811,8 @@ class Transmitter
$type = 'Follow';
} elseif ($item['verb'] == Activity::TAG) {
$type = 'Add';
} elseif ($item['verb'] == Activity::ANNOUNCE) {
$type = 'Announce';
} else {
$type = '';
}
@ -851,20 +857,20 @@ class Transmitter
*/
public static function createActivityFromItem($item_id, $object_mode = false)
{
Logger::info('Fetching activity', ['item' => $item_id]);
$item = Item::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]);
if (!DBA::isResult($item)) {
return false;
}
if ($item['wall'] && ($item['uri'] == $item['parent-uri'])) {
$owner = User::getOwnerDataById($item['uid']);
if (($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) && ($item['author-link'] != $owner['url'])) {
$type = 'Announce';
// Disguise forum posts as reshares. Will later be converted to a real announce
$item['body'] = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'],
$item['plink'], $item['created'], $item['guid']) . $item['body'] . '[/share]';
// In case of a forum post ensure to return the original post if author and forum are on the same machine
if (!empty($item['forum_mode'])) {
$author = Contact::getById($item['author-id'], ['nurl']);
if (!empty($author['nurl'])) {
$self = Contact::selectFirst(['uid'], ['nurl' => $author['nurl'], 'self' => true]);
if (!empty($self['uid'])) {
$item = Item::selectFirst([], ['uri-id' => $item['uri-id'], 'uid' => $self['uid']]);
}
}
}
@ -879,6 +885,7 @@ class Transmitter
unset($data['@context']);
unset($data['signature']);
}
Logger::info('Return stored conversation', ['item' => $item_id]);
return $data;
} elseif (in_array('as:' . $data['type'], Receiver::CONTENT_TYPES)) {
if (!empty($data['@context'])) {
@ -909,7 +916,7 @@ class Transmitter
$data['id'] = $item['uri'] . '/' . $type;
$data['type'] = $type;
if (Item::isForumPost($item) && ($type != 'Announce')) {
if (($type != 'Announce') || ($item['gravity'] != GRAVITY_PARENT)) {
$data['actor'] = $item['author-link'];
} else {
$data['actor'] = $item['owner-link'];
@ -926,7 +933,11 @@ class Transmitter
} elseif ($data['type'] == 'Add') {
$data = self::createAddTag($item, $data);
} elseif ($data['type'] == 'Announce') {
$data = self::createAnnounce($item, $data);
if ($item['verb'] == ACTIVITY::ANNOUNCE) {
$data['object'] = $item['thr-parent'];
} else {
$data = self::createAnnounce($item, $data);
}
} elseif ($data['type'] == 'Follow') {
$data['object'] = $item['parent-uri'];
} elseif ($data['type'] == 'Undo') {
@ -947,7 +958,10 @@ class Transmitter
$owner = User::getOwnerDataById($uid);
if (!$object_mode && !empty($owner)) {
Logger::info('Fetched activity', ['item' => $item_id, 'uid' => $uid]);
// We don't sign if we aren't the actor. This is important for relaying content especially for forums
if (!$object_mode && !empty($owner) && ($data['actor'] == $owner['url'])) {
return LDSignature::sign($data, $owner);
} else {
return $data;
@ -1009,6 +1023,9 @@ class Transmitter
$tags[] = ['type' => 'Hashtag', 'href' => $url, 'name' => '#' . $term['name']];
} else {
$contact = Contact::getByURL($term['url'], false, ['addr']);
if (empty($contact)) {
continue;
}
if (!empty($contact['addr'])) {
$mention = '@' . $contact['addr'];
} else {
@ -1491,6 +1508,10 @@ class Transmitter
*/
public static function isAnnounce($item)
{
if ($item['verb'] == Activity::ANNOUNCE) {
return true;
}
$announce = self::getAnnounceArray($item);
if (empty($announce)) {
return false;