}
// When we hide our friends we will only show the pure number but don't allow more.
- $show_contacts = empty($owner['hide-friends']);
+ $show_contacts = ActivityPub::isAcceptedRequester($owner['uid']) && empty($owner['hide-friends']);
// Allow fetching the contact list when the requester is part of the list.
if (($owner['page-flags'] == User::PAGE_FLAGS_PRVGROUP) && !empty($requester)) {
return $data;
}
- /**
- * Public posts for the given owner
- *
- * @param array $owner Owner array
- * @param integer $uid User id
- * @param integer $page Page number
- * @param integer $max_id Maximum ID
- * @param string $requester URL of requesting account
- * @param boolean $nocache Wether to bypass caching
- * @return array of posts
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- * @throws \ImagickException
- */
- public static function getOutbox(array $owner, int $uid, int $page = null, int $max_id = null, string $requester = ''): array
- {
- $condition = ['gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT], 'private' => [Item::PUBLIC, Item::UNLISTED]];
-
- if (!empty($requester)) {
- $requester_id = Contact::getIdForURL($requester, $owner['uid']);
- if (!empty($requester_id)) {
- $permissionSets = DI::permissionSet()->selectByContactId($requester_id, $owner['uid']);
- if (!empty($permissionSets)) {
- $condition = ['psid' => array_merge($permissionSets->column('id'),
- [DI::permissionSet()->selectPublicForUser($owner['uid'])])];
- }
- }
- }
-
- $condition = array_merge($condition, [
- 'uid' => $owner['uid'],
- 'author-id' => Contact::getIdForURL($owner['url'], 0, false),
- 'gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT],
- 'network' => Protocol::FEDERATED,
- 'parent-network' => Protocol::FEDERATED,
- 'origin' => true,
- 'deleted' => false,
- 'visible' => true
- ]);
-
- $apcontact = APContact::getByURL($owner['url']);
-
- return self::getCollection($condition, DI::baseUrl() . '/outbox/' . $owner['nickname'], $page, $max_id, $uid, $apcontact['statuses_count']);
- }
-
- public static function getInbox(int $uid, int $page = null, int $max_id = null)
- {
- $owner = User::getOwnerDataById($uid);
-
- $condition = ['gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT], 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN], 'uid' => $uid];
-
- return self::getCollection($condition, DI::baseUrl() . '/inbox/' . $owner['nickname'], $page, $max_id, $uid, null);
- }
-
- public static function getPublicInbox(int $uid, int $page = null, int $max_id = null)
- {
- $condition = ['gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT], 'private' => Item::PUBLIC,
- 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN], 'author-blocked' => false, 'author-hidden' => false];
-
- return self::getCollection($condition, DI::baseUrl() . '/inbox', $page, $max_id, $uid, null);
- }
-
- private static function getCollection(array $condition, string $path, int $page = null, int $max_id = null, int $uid = null, int $total_items = null)
- {
- $data = ['@context' => ActivityPub::CONTEXT];
- $data['id'] = $path;
- $data['type'] = 'OrderedCollection';
-
- if (!is_null($total_items)) {
- $data['totalItems'] = $total_items;
- }
-
- if (!empty($page)) {
- $data['id'] .= '?' . http_build_query(['page' => $page]);
- }
-
- if (empty($page) && empty($max_id)) {
- $data['first'] = $path . '?page=1';
- } else {
- $data['type'] = 'OrderedCollectionPage';
- $list = [];
-
- if (!empty($max_id)) {
- $condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $max_id]);
- }
-
- if (!empty($page)) {
- $params = ['limit' => [($page - 1) * 20, 20], 'order' => ['uri-id' => true]];
- } else {
- $params = ['limit' => 20, 'order' => ['uri-id' => true]];
- }
-
- if (!is_null($uid)) {
- $items = Post::selectForUser($uid, ['id', 'uri-id'], $condition, $params);
- } else {
- $items = Post::select(['id', 'uri-id'], $condition, $params);
- }
-
- $last_id = 0;
- while ($item = Post::fetch($items)) {
- $activity = self::createActivityFromItem($item['id'], false, !is_null($uid));
- if (!empty($activity)) {
- $list[] = $activity;
- $last_id = $item['uri-id'];
- continue;
- }
- }
- DBA::close($items);
-
- if (count($list) == 20) {
- $data['next'] = $path . '?max_id=' . $last_id;
- }
-
- // Fix the cached total item count when it is lower than the real count
- if (!is_null($total_items)) {
- $total = (($page - 1) * 20) + $data['totalItems'];
- if ($total > $data['totalItems']) {
- $data['totalItems'] = $total;
- }
- }
-
- $data['partOf'] = $path;
-
- $data['orderedItems'] = $list;
- }
-
- return $data;
- }
-
/**
* Public posts for the given owner
*
return [
'type' => 'Service',
'name' => App::PLATFORM . " '" . App::CODENAME . "' " . App::VERSION . '-' . DB_UPDATE_VERSION,
- 'url' => DI::baseUrl()->get()
+ 'url' => (string)DI::baseUrl()
];
}
/**
* Return the ActivityPub profile of the given user
*
- * @param int $uid User ID
+ * @param int $uid User ID
+ * @param bool $full If not full, only the basic information is returned
* @return array with profile data
* @throws HTTPException\NotFoundException
* @throws HTTPException\InternalServerErrorException
*/
- public static function getProfile(int $uid): array
+ public static function getProfile(int $uid, bool $full = true): array
{
$owner = User::getOwnerDataById($uid);
if (!isset($owner['id'])) {
- DI::logger()->error('Unable to find owner data for uid', ['uid' => $uid, 'callstack' => System::callstack(20)]);
+ DI::logger()->error('Unable to find owner data for uid', ['uid' => $uid]);
throw new HTTPException\NotFoundException('User not found.');
}
$data['preferredUsername'] = $owner['nick'];
$data['name'] = $owner['name'];
- if (!empty($owner['country-name'] . $owner['region'] . $owner['locality'])) {
+ if (!$full && !empty($owner['country-name'] . $owner['region'] . $owner['locality'])) {
$data['vcard:hasAddress'] = ['@type' => 'vcard:Home', 'vcard:country-name' => $owner['country-name'],
'vcard:region' => $owner['region'], 'vcard:locality' => $owner['locality']];
}
- if (!empty($owner['about'])) {
+ if ($full && !empty($owner['about'])) {
$data['summary'] = BBCode::convertForUriId($owner['uri-id'] ?? 0, $owner['about'], BBCode::EXTERNAL);
}
- if (!empty($owner['xmpp']) || !empty($owner['matrix'])) {
+ if ($full && (!empty($owner['xmpp']) || !empty($owner['matrix']))) {
$data['vcard:hasInstantMessage'] = [];
if (!empty($owner['xmpp'])) {
'owner' => $owner['url'],
'publicKeyPem' => $owner['pubkey']];
$data['endpoints'] = ['sharedInbox' => DI::baseUrl() . '/inbox'];
- if ($uid != 0) {
+ if ($full && $uid != 0) {
$data['icon'] = ['type' => 'Image', 'url' => User::getAvatarUrl($owner)];
$resourceid = Photo::ridFromURI($owner['photo']);
}
/**
- * Get a minimal actror array for the C2S API
+ * Get a minimal actor array for the C2S API
*
* @param integer $cid
* @return array
* 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)) {
/**
* 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 integer $last_id Last item id for adding receivers
*
* @return array with permission data
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
}
$always_bcc = false;
- $is_forum = false;
+ $is_group = false;
$follower = '';
+ $exclusive = false;
+ $mention = false;
+ $audience = [];
// Check if we should always deliver our stuff via BCC
if (!empty($item['uid'])) {
$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);
$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;
+ }
+
+ if (!$is_group) {
+ $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;
+ }
+ }
+ }
+ }
+ } else {
+ $audience[] = $owner['url'];
}
if (self::isAnnounce($item) || self::isAPPost($last_id)) {
$networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS];
}
- $data = ['to' => [], 'cc' => [], 'bcc' => []];
+ $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_recursive($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')) {
- $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, false);
foreach ($terms as $term) {
$cid = Contact::getIdForURL($term['url'], $item['uid']);
$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')) {
- $data['cc'][] = $profile['followers'];
+ $data['cc'][] = $profile['followers'];
+ $data['audience'][] = $profile['url'];
}
} elseif (($term['type'] == Tag::MENTION) && ($profile['type'] == 'Group')) {
$mention = true;
$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 ($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;
}
}
- if (!empty($item['parent'])) {
- $parents = Post::select(['id', 'author-link', 'owner-link', 'gravity', 'uri'], ['parent' => $item['parent']], ['order' => ['id']]);
+ 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 {
+ $condition = ['parent' => $item['parent']];
+ }
+ $parents = Post::select(['id', 'author-link', 'owner-link', 'gravity', 'uri'], $condition, ['order' => ['id']]);
while ($parent = Post::fetch($parents)) {
if ($parent['gravity'] == Item::GRAVITY_PARENT) {
$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'];
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]);
}
}
- $receivers = ['to' => array_values($data['to']), 'cc' => array_values($data['cc']), 'bcc' => array_values($data['bcc'])];
+ $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) {
+ 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) {
if ($receiver == ActivityPub::PUBLIC_COLLECTION) {
}
}
}
+ }
+
+ /**
+ * 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)
+ {
+ $receivers = [
+ 'to' => [],
+ 'cc' => [],
+ 'bcc' => [],
+ 'audience' => [],
+ ];
+
+ foreach (Tag::getByURIId($uri_id, [Tag::TO, Tag::CC, Tag::BCC, Tag::AUDIENCE]) 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];
+ } 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;
}
}
}
$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)) {
continue;
}
- if ($isforum && ($contact['network'] == Protocol::DFRN)) {
+ if ($isGroup && ($contact['network'] == Protocol::DFRN)) {
continue;
}
* @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, $last_id);
+ $permissions = self::getReceiversForUriId($item['uri-id'], true);
if (empty($permissions)) {
return [];
}
$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;
}
}
if ($item_profile && ($receiver == $item_profile['followers']) && ($uid == $profile_uid)) {
- $inboxes = array_merge($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)) {
} 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;
/**
* Creates the activity or fetches it from the cache
*
- * @param integer $item_id Item id
- * @param boolean $force Force new cache entry
+ * @param integer $item_id Item id
+ * @param boolean $force Force new cache entry
+ * @param boolean $object_mode true = Create the object, false = create the activity with the object
+ * @param boolean $announce_activity true = the announced object is the activity, false = we announce the object link
* @return array|false activity or false on failure
* @throws \Exception
*/
- public static function createCachedActivityFromItem(int $item_id, bool $force = false, bool $object_mode = false)
+ public static function createCachedActivityFromItem(int $item_id, bool $force = false, bool $object_mode = false, $announce_activity = false)
{
- $cachekey = 'APDelivery:createActivity:' . $item_id . ':' . (int)$object_mode;
+ $cachekey = 'APDelivery:createActivity:' . $item_id . ':' . (int)$object_mode . ':' . (int)$announce_activity;
if (!$force) {
$data = DI::cache()->get($cachekey);
}
}
- $data = self::createActivityFromItem($item_id, $object_mode);
+ $data = self::createActivityFromItem($item_id, $object_mode, false, $announce_activity);
DI::cache()->set($cachekey, $data, Duration::QUARTER_HOUR);
return $data;
* Creates an activity array for a given item id
*
* @param integer $item_id
- * @param boolean $object_mode Is the activity item is used inside another object?
- * @param boolean $api_mode "true" if used for the API
+ * @param boolean $object_mode true = Create the object, false = create the activity with the object
+ * @param boolean $api_mode true = used for the API
+ * @param boolean $announce_activity true = the announced object is the activity, false = we announce the object link
* @return false|array
* @throws \Exception
*/
- public static function createActivityFromItem(int $item_id, bool $object_mode = false, $api_mode = false)
+ public static function createActivityFromItem(int $item_id, bool $object_mode = false, $api_mode = false, $announce_activity = false)
{
$condition = ['id' => $item_id];
if (!$api_mode) {
if (!DBA::isResult($item)) {
return false;
}
- return self::createActivityFromArray($item, $object_mode, $api_mode);
+ return self::createActivityFromArray($item, $object_mode, $api_mode, $announce_activity);
}
/**
*
* @param integer $uri_id
* @param integer $uid
- * @param boolean $object_mode Is the activity item is used inside another object?
- * @param boolean $api_mode "true" if used for the API
+ * @param boolean $object_mode true = Create the object, false = create the activity with the object
+ * @param boolean $api_mode true = used for the API
+ * @param boolean $announce_activity true = the announced object is the activity, false = we announce the object link
* @return false|array
* @throws \Exception
*/
- public static function createActivityFromUriId(int $uri_id, int $uid, bool $object_mode = false, $api_mode = false)
+ public static function createActivityFromUriId(int $uri_id, int $uid, bool $object_mode = false, $api_mode = false, $announce_activity = false)
{
$condition = ['uri-id' => $uri_id, 'uid' => [0, $uid]];
if (!$api_mode) {
return false;
}
- return self::createActivityFromArray($item, $object_mode, $api_mode);
+ return self::createActivityFromArray($item, $object_mode, $api_mode, $announce_activity);
}
/**
* Creates an activity array for a given item id
*
* @param integer $item_id
- * @param boolean $object_mode Is the activity item is used inside another object?
- * @param boolean $api_mode "true" if used for the API
+ * @param boolean $object_mode true = Create the object, false = create the activity with the object
+ * @param boolean $api_mode true = used for the API
+ * @param boolean $announce_activity true = the announced object is the activity, false = we announce the object link
* @return false|array
* @throws \Exception
*/
- private static function createActivityFromArray(array $item, bool $object_mode = false, $api_mode = false)
+ private static function createActivityFromArray(array $item, bool $object_mode = false, $api_mode = false, $announce_activity = false)
{
if (!$api_mode && !$item['deleted'] && $item['network'] == Protocol::ACTIVITYPUB) {
$data = Post\Activity::getByURIId($item['uri-id']);
$data = self::createAddTag($item, $data);
} elseif ($data['type'] == 'Announce') {
if ($item['verb'] == ACTIVITY::ANNOUNCE) {
- $data['object'] = $item['thr-parent'];
+ if ($announce_activity) {
+ $anounced_item = Post::selectFirst(['uid'], ['uri-id' => $item['thr-parent-id'], 'origin' => true]);
+ $data['object'] = self::createActivityFromUriId($item['thr-parent-id'], $anounced_item['uid'] ?? 0);
+ unset($data['object']['@context']);
+ } else {
+ $data['object'] = $item['thr-parent'];
+ }
} else {
$data = self::createAnnounce($item, $data, $api_mode);
}
$data['name'] = BBCode::toPlaintext($item['title'], false);
}
- $permission_block = self::createPermissionBlockForItem($item, false);
+ $permission_block = self::getReceiversForUriId($item['uri-id'], false);
$real_quote = false;
+ $item = Post\Media::addHTMLAttachmentToItem($item);
+
$body = $item['body'];
if ($type == 'Note') {
if ($type == 'Page') {
// When we transmit "Page" posts we have to remove the attachment.
// The attachment contains the link that we already transmit in the "url" field.
- $body = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", '', $body);
+ $body = BBCode::removeAttachment($body);
}
$body = BBCode::setMentionsToNicknames($body);
- if (!empty($item['quote-uri-id'])) {
+ if (!empty($item['quote-uri-id']) && ($item['quote-uri-id'] != $item['uri-id'])) {
if (Post::exists(['uri-id' => $item['quote-uri-id'], 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN]])) {
$real_quote = true;
$data['quoteUrl'] = $item['quote-uri'];
if (!empty($language)) {
$richbody = BBCode::setMentionsToNicknames($item['body'] ?? '');
$richbody = Post\Media::removeFromEndOfBody($richbody);
- if (!empty($item['quote-uri-id'])) {
+ if (!empty($item['quote-uri-id']) && ($item['quote-uri-id'] != $item['uri-id'])) {
if ($real_quote) {
$richbody = DI::contentItem()->addShareLink($richbody, $item['quote-uri-id']);
} else {
$richbody = DI::contentItem()->addSharedPost($item, $richbody);
}
}
- $richbody = BBCode::removeAttachment($richbody);
+ $richbody = BBCode::replaceAttachment($richbody);
$data['contentMap'][$language] = BBCode::convertForUriId($item['uri-id'], $richbody, BBCode::EXTERNAL);
}
- if (!empty($item['quote-uri-id'])) {
+ if (!empty($item['quote-uri-id']) && ($item['quote-uri-id'] != $item['uri-id'])) {
$source = DI::contentItem()->addSharedPost($item, $item['body']);
} else {
$source = $item['body'];
$item['body'] = $announce['comment'] . "\n" . $announce['object']['plink'];
$activity['object'] = self::createNote($item, $api_mode);
- /// @todo Finally descide how to implement this in AP. This is a possible way:
+ /// @todo Finally decide how to implement this in AP. This is a possible way:
$activity['object']['attachment'][] = self::createNote($announce['object']);
$activity['object']['source']['content'] = $orig_body;
}
/**
- * Return announce related data if the item is an annunce
+ * Return announce related data if the item is an announce
*
* @param array $item
* @return array Announcement array