/**
* Returns the combined list of contact ids from a group id list
*
- * @param int $uid User id
- * @param array $group_ids Groups ids
- * @param boolean $check_dead Whether check "dead" records (?)
+ * @param int $uid User id
+ * @param array $group_ids Groups ids
+ * @param boolean $check_dead Whether check "dead" records (?)
+ * @param boolean $expand_followers Expand the list of followers
* @return array
* @throws \Exception
*/
- public static function expand(int $uid, array $group_ids, bool $check_dead = false): array
+ public static function expand(int $uid, array $group_ids, bool $check_dead = false, bool $expand_followers = true): array
{
if (!is_array($group_ids) || !count($group_ids)) {
return [];
}
- $return = [];
- $pubmail = false;
- $networks = Protocol::SUPPORT_PRIVATE;
+ $return = [];
+ $pubmail = false;
+ $followers_collection = false;
+ $networks = Protocol::SUPPORT_PRIVATE;
$mailacct = DBA::selectFirst('mailacct', ['pubmail'], ['`uid` = ? AND `server` != ""', $uid]);
if (DBA::isResult($mailacct)) {
$key = array_search(self::FOLLOWERS, $group_ids);
if ($key !== false) {
- $followers = Contact::selectToArray(['id'], [
- 'uid' => $uid,
- 'rel' => [Contact::FOLLOWER, Contact::FRIEND],
- 'network' => $networks,
- 'contact-type' => [Contact::TYPE_UNKNOWN, Contact::TYPE_PERSON],
- 'archive' => false,
- 'pending' => false,
- 'blocked' => false,
- ]);
-
- foreach ($followers as $follower) {
- $return[] = $follower['id'];
+ if ($expand_followers) {
+ $followers = Contact::selectToArray(['id'], [
+ 'uid' => $uid,
+ 'rel' => [Contact::FOLLOWER, Contact::FRIEND],
+ 'network' => $networks,
+ 'contact-type' => [Contact::TYPE_UNKNOWN, Contact::TYPE_PERSON],
+ 'archive' => false,
+ 'pending' => false,
+ 'blocked' => false,
+ ]);
+
+ foreach ($followers as $follower) {
+ $return[] = $follower['id'];
+ }
+ } else {
+ $followers_collection = true;
}
-
unset($group_ids[$key]);
}
$return = Contact::pruneUnavailable($return);
}
+ if ($followers_collection) {
+ $return[] = -1;
+ }
+
return $return;
}
/**
* Returns an array of contact-ids that are allowed to see this object
*
- * @param array $obj Item array with at least uid, allow_cid, allow_gid, deny_cid and deny_gid
- * @param bool $check_dead Prunes unavailable contacts from the result
+ * @param array $obj Item array with at least uid, allow_cid, allow_gid, deny_cid and deny_gid
+ * @param bool $check_dead Prunes unavailable contacts from the result
+ * @param bool $expand_followers Expand the list of followers
* @return array
* @throws \Exception
*/
- public static function enumeratePermissions(array $obj, bool $check_dead = false): array
+ public static function enumeratePermissions(array $obj, bool $check_dead = false, bool $expand_followers = true): array
{
$aclFormatter = DI::aclFormatter();
+ if (!$expand_followers && (!empty($obj['deny_cid']) || !empty($obj['deny_gid']))) {
+ $expand_followers = true;
+ }
+
$allow_people = $aclFormatter->expand($obj['allow_cid']);
- $allow_groups = Group::expand($obj['uid'], $aclFormatter->expand($obj['allow_gid']), $check_dead);
+ $allow_groups = Group::expand($obj['uid'], $aclFormatter->expand($obj['allow_gid']), $check_dead, $expand_followers);
$deny_people = $aclFormatter->expand($obj['deny_cid']);
$deny_groups = Group::expand($obj['uid'], $aclFormatter->expand($obj['deny_gid']), $check_dead);
$recipients = array_unique(array_merge($allow_people, $allow_groups));
/**
* Creates an array of permissions from an item thread
*
- * @param array $item Item array
- * @param boolean $blindcopy addressing via "bcc" or "cc"?
- * @param integer $last_id Last item id for adding receivers
+ * @param array $item Item array
+ * @param boolean $blindcopy addressing via "bcc" or "cc"?
+ * @param boolean $expand_followers Expand the list of followers
+ * @param integer $last_id Last item id for adding receivers
*
* @return array with permission data
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- private static function createPermissionBlockForItem(array $item, bool $blindcopy, int $last_id = 0): array
+ private static function createPermissionBlockForItem(array $item, bool $blindcopy, bool $expand_followers, int $last_id = 0): array
{
if ($last_id == 0) {
$last_id = $item['id'];
$networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS];
}
- $data = ['to' => [], 'cc' => [], 'bcc' => []];
+ $data = ['to' => [], 'cc' => [], 'bcc' => [] , 'audience' => []];
if ($item['gravity'] == Item::GRAVITY_PARENT) {
$actor_profile = APContact::getByURL($item['owner-link']);
if ($term['type'] == Tag::EXCLUSIVE_MENTION) {
$exclusive = true;
if (!empty($profile['followers']) && ($profile['type'] == 'Group')) {
- $data['cc'][] = $profile['followers'];
+ $data['cc'][] = $profile['followers'];
+ $data['audience'][] = $profile['url'];
}
} elseif (($term['type'] == Tag::MENTION) && ($profile['type'] == 'Group')) {
$mention = true;
$data['to'][] = $profile['url'];
}
}
+ if (!$exclusive && ($item['private'] == Item::UNLISTED)) {
+ $data['to'][] = $actor_profile['followers'];
+ }
} else {
- $receiver_list = Item::enumeratePermissions($item, true);
+ $receiver_list = Item::enumeratePermissions($item, true, $expand_followers);
foreach ($terms as $term) {
$cid = Contact::getIdForURL($term['url'], $item['uid']);
if ($term['type'] == Tag::EXCLUSIVE_MENTION) {
$exclusive = true;
if (!empty($profile['followers']) && ($profile['type'] == 'Group')) {
- $data['cc'][] = $profile['followers'];
+ $data['cc'][] = $profile['followers'];
+ $data['audience'][] = $profile['url'];
}
} elseif (($term['type'] == Tag::MENTION) && ($profile['type'] == 'Group')) {
$mention = true;
$data['cc'][] = $follower;
} elseif (!$exclusive) {
foreach ($receiver_list as $receiver) {
+ if ($receiver == -1) {
+ $data['to'][] = $actor_profile['followers'];
+ continue;
+ }
+
$contact = DBA::selectFirst('contact', ['url', 'hidden', 'network', 'protocol', 'gsid'], ['id' => $receiver, 'network' => Protocol::FEDERATED]);
if (!DBA::isResult($contact) || !self::isAPContact($contact, $networks)) {
continue;
DBA::close($parents);
}
- $data['to'] = array_unique($data['to']);
- $data['cc'] = array_unique($data['cc']);
- $data['bcc'] = array_unique($data['bcc']);
+ $data['to'] = array_unique($data['to']);
+ $data['cc'] = array_unique($data['cc']);
+ $data['bcc'] = array_unique($data['bcc']);
+ $data['audience'] = array_unique($data['audience']);
if (($key = array_search($item['author-link'], $data['to'])) !== false) {
unset($data['to'][$key]);
unset($data['bcc'][$key]);
}
+ if (($key = array_search($item['author-link'], $data['audience'])) !== false) {
+ unset($data['audience'][$key]);
+ }
+
foreach ($data['to'] as $to) {
if (($key = array_search($to, $data['cc'])) !== false) {
unset($data['cc'][$key]);
$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];
+ }
+ }
+
if (!$blindcopy) {
unset($receivers['bcc']);
}
*/
public static function fetchTargetInboxes(array $item, int $uid, bool $personal = false, int $last_id = 0): array
{
- $permissions = self::createPermissionBlockForItem($item, true, $last_id);
+ $permissions = self::createPermissionBlockForItem($item, true, true, $last_id);
if (empty($permissions)) {
return [];
}
$data['actor'] = $mail['author-link'];
$data['published'] = DateTimeFormat::utc($mail['created'] . '+00:00', DateTimeFormat::ATOM);
$data['instrument'] = self::getService();
- $data = array_merge($data, self::createPermissionBlockForItem($mail, true));
+ $data = array_merge($data, self::createPermissionBlockForItem($mail, true, false));
if (empty($data['to']) && !empty($data['cc'])) {
$data['to'] = $data['cc'];
$data['instrument'] = self::getService();
- $data = array_merge($data, self::createPermissionBlockForItem($item, false));
+ $data = array_merge($data, self::createPermissionBlockForItem($item, false, false));
if (in_array($data['type'], ['Create', 'Update', 'Delete'])) {
$data['object'] = self::createNote($item, $api_mode);
$data['name'] = BBCode::toPlaintext($item['title'], false);
}
- $permission_block = self::createPermissionBlockForItem($item, false);
+ $permission_block = self::createPermissionBlockForItem($item, false, false);
$real_quote = false;