*/
public static function normalizeMentionLinks(string $body): string
{
- return preg_replace('%\[url=([^\[\]]*)]([#@!])(.*?)\[/url]%ism', '$2[url=$1]$3[/url]', $body);
+ $body = preg_replace('%\[url=([^\[\]]*)]([#@!])(.*?)\[/url]%ism', '$2[url=$1]$3[/url]', $body);
+ $body = preg_replace('%([#@!])\[zrl=([^\[\]]*)](.*?)\[/zrl]%ism', '$1[url=$2]$3[/url]', $body);
+ return $body;
}
/**
$item['changed'] = DateTimeFormat::utcNow();
$item['edited'] = DateTimeFormat::utc($activity['updated']);
- Post\Media::deleteByURIId($item['uri-id'], [Post\Media::AUDIO, Post\Media::VIDEO, Post\Media::IMAGE]);
+ Post\Media::deleteByURIId($item['uri-id'], [Post\Media::AUDIO, Post\Media::VIDEO, Post\Media::IMAGE, Post\Media::HTML]);
$item = self::processContent($activity, $item);
if (empty($item)) {
Queue::remove($activity);
$item['post-type'] = Item::PT_NOTE;
}
- $item['isForum'] = false;
+ $item['isGroup'] = false;
if (!empty($activity['thread-completion'])) {
if ($activity['thread-completion'] != $item['owner-id']) {
$item['owner-id'] = $item['author-id'];
} else {
$actor = APContact::getByURL($item['owner-link'], false);
- $item['isForum'] = ($actor['type'] ?? 'Person') == 'Group';
+ $item['isGroup'] = ($actor['type'] ?? 'Person') == 'Group';
+ }
+
+ if (!$item['isGroup'] && !empty($activity['receiver_urls']['as:audience'])) {
+ foreach ($activity['receiver_urls']['as:audience'] as $audience) {
+ $actor = APContact::getByURL($audience, false);
+ if (($actor['type'] ?? 'Person') == 'Group') {
+ Logger::debug('Set owner to audience', ['audience' => $audience, 'actor' => $activity['actor'], 'author' => $activity['author']]);
+ $item['isGroup'] = true;
+ $item['owner-link'] = $audience;
+ $item['owner-id'] = Contact::getIdForURL($audience);
+ }
+ }
}
$item['uri'] = $activity['id'];
if ($id) {
$shared_item = Post::selectFirst(['uri-id'], ['id' => $id]);
$item['quote-uri-id'] = $shared_item['uri-id'];
+ } elseif ($uri_id = ItemURI::getIdByURI($activity['quote-url'], false)) {
+ Logger::info('Quote was not fetched but the uri-id existed', ['guid' => $item['guid'], 'uri-id' => $item['uri-id'], 'quote' => $activity['quote-url'], 'uri-id' => $uri_id]);
+ $item['quote-uri-id'] = $uri_id;
} else {
Logger::info('Quote was not fetched', ['guid' => $item['guid'], 'uri-id' => $item['uri-id'], 'quote' => $activity['quote-url']]);
}
Logger::warning('Unknown parent item.', ['uri' => $parent_uri]);
return false;
}
- if (!empty($activity['type']) && in_array($activity['type'], Receiver::CONTENT_TYPES) && ($item['private'] == 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;
- }
-
$content = self::removeImplicitMentionsFromBody($content, $parent);
}
$item['content-warning'] = HTML::toBBCode($activity['summary'] ?? '');
return true;
}
- if (in_array($activity['completion-mode'] ?? Receiver::COMPLETION_NONE, [Receiver::COMPLETION_MANUAL, Receiver::COMPLETION_ANNOUCE])) {
+ if (in_array($activity['completion-mode'] ?? Receiver::COMPLETION_NONE, [Receiver::COMPLETION_MANUAL, Receiver::COMPLETION_ANNOUNCE])) {
// Manual completions and completions caused by reshares are allowed without any further checks.
Logger::debug('Message is in completion mode - accepted', ['mode' => $activity['completion-mode'], 'uri-id' => $item['uri-id'], 'guid' => $item['guid'], 'url' => $item['uri']]);
return true;
case Receiver::TARGET_BCC:
$item['post-reason'] = Item::PR_BCC;
break;
+ case Receiver::TARGET_AUDIENCE:
+ $item['post-reason'] = Item::PR_AUDIENCE;
+ break;
case Receiver::TARGET_FOLLOWER:
$item['post-reason'] = Item::PR_FOLLOWER;
break;
$item['causer-id'] = ($item['gravity'] == Item::GRAVITY_PARENT) ? $item['owner-id'] : $item['author-id'];
}
- if ($item['isForum'] ?? false) {
- $item['contact-id'] = Contact::getIdForURL($activity['actor'], $receiver);
+ if ($item['isGroup'] ?? false) {
+ $item['contact-id'] = Contact::getIdForURL($item['owner-link'], $receiver);
} else {
- $item['contact-id'] = Contact::getIdForURL($activity['author'], $receiver);
+ $item['contact-id'] = Contact::getIdForURL($item['author-link'], $receiver);
}
if (($receiver != 0) && empty($item['contact-id'])) {
continue;
}
- if (($receiver != 0) && ($item['gravity'] == Item::GRAVITY_PARENT) && !in_array($item['post-reason'], [Item::PR_FOLLOWER, Item::PR_TAG, item::PR_TO, Item::PR_CC])) {
- if (!($item['isForum'] ?? false)) {
+ if (($receiver != 0) && ($item['gravity'] == Item::GRAVITY_PARENT) && !in_array($item['post-reason'], [Item::PR_FOLLOWER, Item::PR_TAG, item::PR_TO, Item::PR_CC, Item::PR_AUDIENCE])) {
+ if (!($item['isGroup'] ?? false)) {
if ($item['post-reason'] == Item::PR_BCC) {
Logger::info('Top level post via BCC from a non sharer, ignoring', ['uid' => $receiver, 'contact' => $item['contact-id'], 'url' => $item['uri']]);
continue;
}
}
- $is_forum = false;
+ $isGroup = false;
$user = User::getById($receiver, ['account-type']);
if (!empty($user['account-type'])) {
- $is_forum = ($user['account-type'] == User::ACCOUNT_TYPE_COMMUNITY);
+ $isGroup = ($user['account-type'] == User::ACCOUNT_TYPE_COMMUNITY);
}
if ((DI::pConfig()->get($receiver, 'system', 'accept_only_sharer') == Item::COMPLETION_NONE)
- && ((!$is_forum && !($item['isForum'] ?? false) && ($activity['type'] != 'as:Announce'))
+ && ((!$isGroup && !($item['isGroup'] ?? false) && ($activity['type'] != 'as:Announce'))
|| !Contact::isSharingByURL($activity['actor'], $receiver))) {
- Logger::info('Actor is a non sharer, is no forum or it is no announce', ['uid' => $receiver, 'actor' => $activity['actor'], 'url' => $item['uri'], 'type' => $activity['type']]);
+ Logger::info('Actor is a non sharer, is no group or it is no announce', ['uid' => $receiver, 'actor' => $activity['actor'], 'url' => $item['uri'], 'type' => $activity['type']]);
continue;
}
// Store send a follow request for every reshare - but only when the item had been stored
if ($stored && ($item['private'] != Item::PRIVATE) && ($item['gravity'] == Item::GRAVITY_PARENT) && !empty($item['author-link']) && ($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)
+ // We send automatic follow requests for reshared messages. (We don't need though for group posts)
if ($author['type'] != 'Group') {
Logger::info('Send follow request', ['uri' => $item['uri'], 'stored' => $stored, 'to' => $item['author-link']]);
ActivityPub\Transmitter::sendFollowObject($item['uri'], $item['author-link']);
public static function storeReceivers(int $uriid, array $receivers)
{
- foreach (['as:to' => Tag::TO, 'as:cc' => Tag::CC, 'as:bto' => Tag::BTO, 'as:bcc' => Tag::BCC] as $element => $type) {
+ foreach (['as:to' => Tag::TO, 'as:cc' => Tag::CC, 'as:bto' => Tag::BTO, 'as:bcc' => Tag::BCC, 'as:audience' => Tag::AUDIENCE, 'as:attributedTo' => Tag::ATTRIBUTED] as $element => $type) {
if (!empty($receivers[$element])) {
foreach ($receivers[$element] as $receiver) {
if ($receiver == ActivityPub::PUBLIC_COLLECTION) {
$name = Receiver::PUBLIC_COLLECTION;
} elseif ($path = parse_url($receiver, PHP_URL_PATH)) {
$name = trim($path, '/');
+ } elseif ($host = parse_url($receiver, PHP_URL_HOST)) {
+ $name = $host;
} else {
- Logger::warning('Unable to coerce name from receiver', ['receiver' => $receiver]);
+ Logger::warning('Unable to coerce name from receiver', ['element' => $element, 'type' => $type, 'receiver' => $receiver]);
$name = '';
}
$activity['id'] = $object['id'];
$activity['to'] = $object['to'] ?? [];
$activity['cc'] = $object['cc'] ?? [];
+ $activity['audience'] = $object['audience'] ?? [];
$activity['actor'] = $actor;
$activity['object'] = $object;
$activity['published'] = $published;