*
* @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, bool $expand_followers, int $last_id = 0): array
+ private static function createPermissionBlockForItem(array $item, bool $blindcopy, int $last_id = 0): array
{
if ($last_id == 0) {
$last_id = $item['id'];
$data['to'][] = $actor_profile['followers'];
}
} else {
- $receiver_list = Item::enumeratePermissions($item, true, $expand_followers);
+ $receiver_list = Item::enumeratePermissions($item, true, false);
foreach ($terms as $term) {
$cid = Contact::getIdForURL($term['url'], $item['uid']);
unset($receivers['bcc']);
}
+ if (!$blindcopy && count($receivers['audience']) == 1) {
+ $receivers['audience'] = $receivers['audience'][0];
+ } elseif (!$receivers['audience']) {
+ unset($receivers['audience']);
+ }
+
+ return $receivers;
+ }
+
+ /**
+ * Store the receivers for the given item
+ *
+ * @param array $item
+ * @return void
+ */
+ public static function storeReceiversForItem(array $item)
+ {
+ $receivers = self::createPermissionBlockForItem($item, true);
+ if (empty($receivers)) {
+ return;
+ }
+
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) {
}
}
}
+ }
+
+ /**
+ * Get a list of receivers for the provided uri-id
+ *
+ * @param array $item
+ * @param boolean $blindcopy
+ * @return void
+ */
+ public static function getReceiversForUriId(int $uri_id, bool $blindcopy)
+ {
+ $tags = Tag::getByURIId($uri_id, [Tag::TO, Tag::CC, Tag::BCC, Tag::AUDIENCE]);
+ if (empty($tags)) {
+ Logger::debug('No receivers found', ['uri-id' => $uri_id]);
+ $post = Post::selectFirst([Item::DELIVER_FIELDLIST], ['uri-id' => $uri_id, 'origin' => true]);
+ if (!empty($post)) {
+ ActivityPub\Transmitter::storeReceiversForItem($post);
+ $tags = Tag::getByURIId($uri_id, [Tag::TO, Tag::CC, Tag::BCC, Tag::AUDIENCE]);
+ Logger::debug('Receivers are created', ['uri-id' => $uri_id, 'receivers' => count($tags)]);
+ } else {
+ Logger::debug('Origin item not found', ['uri-id' => $uri_id]);
+ }
+ }
+
+ $receivers = [
+ 'to' => [],
+ 'cc' => [],
+ 'bcc' => [],
+ 'audience' => [],
+ ];
+
+ foreach ($tags as $receiver) {
+ switch ($receiver['type']) {
+ case Tag::TO:
+ $receivers['to'][] = $receiver['url'];
+ break;
+ case Tag::CC:
+ $receivers['cc'][] = $receiver['url'];
+ break;
+ case Tag::BCC:
+ $receivers['bcc'][] = $receiver['url'];
+ break;
+ case Tag::AUDIENCE:
+ $receivers['audience'][] = $receiver['url'];
+ break;
+ }
+ }
+
+ if (!$blindcopy) {
+ unset($receivers['bcc']);
+ }
if (!$blindcopy && count($receivers['audience']) == 1) {
$receivers['audience'] = $receivers['audience'][0];
}
$condition = [
- 'uid' => $uid,
- 'archive' => false,
- 'pending' => false,
- 'blocked' => false,
- 'network' => Protocol::FEDERATED,
+ 'uid' => $uid,
+ 'self' => false,
+ 'archive' => false,
+ 'pending' => false,
+ 'blocked' => false,
+ 'network' => Protocol::FEDERATED,
+ 'contact-type' => [Contact::TYPE_UNKNOWN, Contact::TYPE_PERSON, Contact::TYPE_NEWS, Contact::TYPE_ORGANISATION],
];
if (!empty($uid)) {
* @param array $item Item array
* @param integer $uid User ID
* @param boolean $personal fetch personal inboxes
- * @param integer $last_id Last item id for adding receivers
* @return array with inboxes
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public static function fetchTargetInboxes(array $item, int $uid, bool $personal = false, int $last_id = 0): array
+ public static function fetchTargetInboxes(array $item, int $uid, bool $personal = false): array
{
- $permissions = self::createPermissionBlockForItem($item, true, true, $last_id);
+ $permissions = self::getReceiversForUriId($item['uri-id'], true);
if (empty($permissions)) {
return [];
}
}
if ($item_profile && ($receiver == $item_profile['followers']) && ($uid == $profile_uid)) {
- $inboxes = array_merge_recursive($inboxes, self::fetchTargetInboxesforUser($uid, $personal, self::isAPPost($last_id)));
+ $inboxes = array_merge_recursive($inboxes, self::fetchTargetInboxesforUser($uid, $personal, true));
} else {
$profile = APContact::getByURL($receiver, false);
if (!empty($profile)) {
$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, false));
+ $data = array_merge($data, self::createPermissionBlockForItem($mail, true));
if (empty($data['to']) && !empty($data['cc'])) {
$data['to'] = $data['cc'];
$data['instrument'] = self::getService();
- $data = array_merge($data, self::createPermissionBlockForItem($item, false, false));
+ $data = array_merge($data, self::createPermissionBlockForItem($item, 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, false);
+ $permission_block = self::getReceiversForUriId($item['uri-id'], false);
$real_quote = false;
if (!empty($item['language'])) {
$languages = array_keys(json_decode($item['language'], true));
if (!empty($languages[0])) {
- return $languages[0];
+ return DI::l10n()->toISO6391($languages[0]);
}
}
if (!empty($item['uid'])) {
$user = DBA::selectFirst('user', ['language'], ['uid' => $item['uid']]);
if (!empty($user['language'])) {
- return $user['language'];
+ return DI::l10n()->toISO6391($user['language']);
}
}
// And finally just use the system language
- return DI::config()->get('system', 'language');
+ return DI::l10n()->toISO6391(DI::config()->get('system', 'language'));
}
/**