* Returns an array with permissions of the thread parent of the given item array
*
* @param array $item
- * @param bool $is_forum_thread
*
* @return array with permissions
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- private static function fetchPermissionBlockFromThreadParent(array $item, bool $is_forum_thread): array
+ private static function fetchPermissionBlockFromThreadParent(array $item, bool $is_group_thread): array
{
if (empty($item['thr-parent-id'])) {
return [];
'cc' => [],
'bto' => [],
'bcc' => [],
+ 'audience' => [],
];
$parent_profile = APContact::getByURL($parent['author-link']);
$exclude[] = $item['owner-link'];
}
- $type = [Tag::TO => 'to', Tag::CC => 'cc', Tag::BTO => 'bto', Tag::BCC => 'bcc'];
- foreach (Tag::getByURIId($item['thr-parent-id'], [Tag::TO, Tag::CC, Tag::BTO, Tag::BCC]) as $receiver) {
+ $type = [Tag::TO => 'to', Tag::CC => 'cc', Tag::BTO => 'bto', Tag::BCC => 'bcc', Tag::AUDIENCE => 'audience'];
+ foreach (Tag::getByURIId($item['thr-parent-id'], [Tag::TO, Tag::CC, Tag::BTO, Tag::BCC, Tag::AUDIENCE]) as $receiver) {
if (!empty($parent_profile['followers']) && $receiver['url'] == $parent_profile['followers'] && !empty($item_profile['followers'])) {
- if (!$is_forum_thread) {
+ if (!$is_group_thread) {
$permissions[$type[$receiver['type']]][] = $item_profile['followers'];
}
} elseif (!in_array($receiver['url'], $exclude)) {
}
$always_bcc = false;
- $is_forum = false;
+ $is_group = false;
$follower = '';
// Check if we should always deliver our stuff via BCC
$owner = User::getOwnerDataById($item['uid']);
if (!empty($owner)) {
$always_bcc = $owner['hide-friends'];
- $is_forum = ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) && $owner['manually-approve'];
+ $is_group = ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) && $owner['manually-approve'];
$profile = APContact::getByURL($owner['url'], false);
$follower = $profile['followers'] ?? '';
$parent = Post::selectFirst(['causer-link', 'post-reason'], ['id' => $item['parent']]);
if (!empty($parent) && ($parent['post-reason'] == Item::PR_ANNOUNCEMENT) && !empty($parent['causer-link'])) {
$profile = APContact::getByURL($parent['causer-link'], false);
- $is_forum_thread = isset($profile['type']) && $profile['type'] == 'Group';
+ $is_group_thread = isset($profile['type']) && $profile['type'] == 'Group';
} else {
- $is_forum_thread = false;
+ $is_group_thread = false;
+ }
+
+ $exclusive = false;
+ $mention = false;
+ $audience = [];
+
+ $parent_tags = Tag::getByURIId($item['parent-uri-id'], [Tag::AUDIENCE, Tag::MENTION]);
+ if (!empty($parent_tags)) {
+ $is_group_thread = false;
+ foreach ($parent_tags as $tag) {
+ if ($tag['type'] != Tag::AUDIENCE) {
+ continue;
+ }
+ $profile = APContact::getByURL($tag['url'], false);
+ if (!empty($profile) && ($profile['type'] == 'Group')) {
+ $audience[] = $tag['url'];
+ $is_group_thread = true;
+ }
+ }
+ if ($is_group_thread) {
+ foreach ($parent_tags as $tag) {
+ if (($tag['type'] == Tag::MENTION) && in_array($tag['url'], $audience)) {
+ $mention = true;
+ }
+ }
+ $exclusive = !$mention;
+ }
+ } elseif ($is_group_thread) {
+ foreach (Tag::getByURIId($item['parent-uri-id'], [Tag::MENTION, Tag::EXCLUSIVE_MENTION]) as $term) {
+ $profile = APContact::getByURL($term['url'], false);
+ if (!empty($profile) && ($profile['type'] == 'Group')) {
+ if ($term['type'] == Tag::EXCLUSIVE_MENTION) {
+ $audience[] = $term['url'];
+ $exclusive = true;
+ } elseif ($term['type'] == Tag::MENTION) {
+ $mention = true;
+ }
+ }
+ }
}
if (self::isAnnounce($item) || self::isAPPost($last_id)) {
$networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS];
}
- $data = ['to' => [], 'cc' => [], 'bcc' => [] , 'audience' => []];
+ $data = ['to' => [], 'cc' => [], 'bcc' => [] , 'audience' => $audience];
if ($item['gravity'] == Item::GRAVITY_PARENT) {
$actor_profile = APContact::getByURL($item['owner-link']);
$actor_profile = APContact::getByURL($item['author-link']);
}
- $exclusive = false;
- $mention = false;
-
- if ($is_forum_thread) {
- foreach (Tag::getByURIId($item['parent-uri-id'], [Tag::MENTION, Tag::EXCLUSIVE_MENTION]) as $term) {
- $profile = APContact::getByURL($term['url'], false);
- if (!empty($profile) && ($profile['type'] == 'Group')) {
- if ($term['type'] == Tag::EXCLUSIVE_MENTION) {
- $exclusive = true;
- } elseif ($term['type'] == Tag::MENTION) {
- $mention = true;
- }
- }
- }
- }
-
- $terms = Tag::getByURIId($item['uri-id'], [Tag::MENTION, Tag::IMPLICIT_MENTION, Tag::EXCLUSIVE_MENTION]);
+ $terms = Tag::getByURIId($item['uri-id'], [Tag::MENTION, Tag::IMPLICIT_MENTION, Tag::EXCLUSIVE_MENTION, Tag::AUDIENCE]);
if ($item['private'] != Item::PRIVATE) {
// Directly mention the original author upon a quoted reshare.
$data['cc'][] = $announce['actor']['url'];
}
- $data = array_merge($data, self::fetchPermissionBlockFromThreadParent($item, $is_forum_thread));
+ if (!$exclusive) {
+ $data = array_merge($data, self::fetchPermissionBlockFromThreadParent($item, $is_group_thread));
+ }
// Check if the item is completely public or unlisted
if ($item['private'] == Item::PUBLIC) {
foreach ($terms as $term) {
$profile = APContact::getByURL($term['url'], false);
if (!empty($profile)) {
+ if (($term['type'] == Tag::AUDIENCE) && ($profile['type'] == 'Group')) {
+ $data['audience'][] = $profile['url'];
+ }
if ($term['type'] == Tag::EXCLUSIVE_MENTION) {
$exclusive = true;
if (!empty($profile['followers']) && ($profile['type'] == 'Group')) {
$profile = APContact::getByURL($term['url'], false);
if (!empty($profile)) {
+ if (($term['type'] == Tag::AUDIENCE) && ($profile['type'] == 'Group')) {
+ $data['audience'][] = $profile['url'];
+ }
if ($term['type'] == Tag::EXCLUSIVE_MENTION) {
$exclusive = true;
if (!empty($profile['followers']) && ($profile['type'] == 'Group')) {
$exclusive = false;
}
- if ($is_forum && !$exclusive && !empty($follower)) {
+ if ($is_group && !$exclusive && !empty($follower)) {
$data['cc'][] = $follower;
} elseif (!$exclusive) {
foreach ($receiver_list as $receiver) {
}
}
- if (!empty($item['parent'])) {
+ if (!empty($item['parent']) && (!$exclusive || ($item['private'] == Item::PRIVATE))) {
if ($item['private'] == Item::PRIVATE) {
$condition = ['parent' => $item['parent'], 'uri-id' => $item['thr-parent-id']];
} else {
$profile = APContact::getByURL($parent['owner-link'], false);
if (!empty($profile)) {
if ($item['gravity'] != Item::GRAVITY_PARENT) {
- // Comments to forums are directed to the forum
- // But comments to forums aren't directed to the followers collection
- // This rule is only valid when the actor isn't the forum.
- // The forum needs to transmit their content to their followers.
+ // Comments to groups are directed to the group
+ // But comments to groups aren't directed to the followers collection
+ // This rule is only valid when the actor isn't the group.
+ // The group 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'];
- if (($item['private'] != Item::PRIVATE) && !empty($actor_profile['followers']) && (!$exclusive || !$is_forum_thread)) {
+ if (($item['private'] != Item::PRIVATE) && !empty($actor_profile['followers']) && (!$exclusive || !$is_group_thread)) {
$data['cc'][] = $actor_profile['followers'];
}
}
- } elseif (!$exclusive && !$is_forum_thread) {
+ } elseif (!$exclusive && !$is_group_thread) {
// Public thread parent post always are directed to the followers.
if ($item['private'] != Item::PRIVATE) {
$data['cc'][] = $actor_profile['followers'];
}
}
- $receivers = ['to' => array_values($data['to']), 'cc' => array_values($data['cc']), 'bcc' => array_values($data['bcc'])];
-
- if (!empty($data['audience'])) {
- $receivers['audience'] = array_values($data['audience']);
- if (count($receivers['audience']) == 1) {
- $receivers['audience'] = $receivers['audience'][0];
- }
- }
+ $receivers = ['to' => array_values($data['to']), 'cc' => array_values($data['cc']), 'bcc' => array_values($data['bcc']), 'audience' => array_values($data['audience'])];
if (!$blindcopy) {
unset($receivers['bcc']);
}
- foreach (['to' => Tag::TO, 'cc' => Tag::CC, 'bcc' => Tag::BCC] as $element => $type) {
+ foreach (['to' => Tag::TO, 'cc' => Tag::CC, 'bcc' => Tag::BCC, 'audience' => Tag::AUDIENCE] as $element => $type) {
if (!empty($receivers[$element])) {
foreach ($receivers[$element] as $receiver) {
if ($receiver == ActivityPub::PUBLIC_COLLECTION) {
}
}
+ if (!$blindcopy && count($receivers['audience']) == 1) {
+ $receivers['audience'] = $receivers['audience'][0];
+ } elseif (!$receivers['audience']) {
+ unset($receivers['audience']);
+ }
+
return $receivers;
}
{
$inboxes = [];
- $isforum = false;
-
+ $isGroup = false;
if (!empty($item['uid'])) {
$profile = User::getOwnerDataById($item['uid']);
if (!empty($profile)) {
- $isforum = $profile['account-type'] == User::ACCOUNT_TYPE_COMMUNITY;
+ $isGroup = $profile['account-type'] == User::ACCOUNT_TYPE_COMMUNITY;
}
}
continue;
}
- if ($isforum && ($contact['network'] == Protocol::DFRN)) {
+ if ($isGroup && ($contact['network'] == Protocol::DFRN)) {
continue;
}
$profile_uid = User::getIdForURL($item_profile['url']);
- foreach (['to', 'cc', 'bto', 'bcc'] as $element) {
+ foreach (['to', 'cc', 'bto', 'bcc', 'audience'] as $element) {
if (empty($permissions[$element])) {
continue;
}
} else {
$target = $profile['sharedinbox'];
}
- if (!self::archivedInbox($target)) {
+ if (!self::archivedInbox($target) && !in_array($contact['id'], $inboxes[$target] ?? [])) {
$inboxes[$target][] = $contact['id'] ?? 0;
}
}
unset($data['cc']);
unset($data['bcc']);
+ unset($data['audience']);
$object['to'] = $data['to'];
$object['tag'] = [['type' => 'Mention', 'href' => $object['to'][0], 'name' => '']];
unset($object['cc']);
unset($object['bcc']);
+ unset($object['audience']);
$data['directMessage'] = true;