const TARGET_ANSWER = 6;
const TARGET_GLOBAL = 7;
+ const COMPLETION_NONE = 0;
+ const COMPLETION_ANNOUCE = 1;
+ const COMPLETION_RELAY = 2;
+ const COMPLETION_MANUAL = 3;
+ const COMPLETION_AUTO = 4;
+
/**
* Checks incoming message from the inbox
*
return;
}
- $id = Processor::fetchMissingActivity($object_id, [], $actor);
+ $id = Processor::fetchMissingActivity($object_id, [], $actor, self::COMPLETION_RELAY);
if (empty($id)) {
Logger::notice('Relayed message had not been fetched', ['id' => $object_id]);
return;
$reception_types[$data['uid']] = $data['type'] ?? self::TARGET_UNKNOWN;
}
+ $urls = self::getReceiverURL($activity);
+
// When it is a delivery to a personal inbox we add that user to the receivers
if (!empty($uid)) {
$additional = [$uid => $uid];
$receivers = array_replace($receivers, $additional);
if (empty($activity['thread-completion']) && (empty($reception_types[$uid]) || in_array($reception_types[$uid], [self::TARGET_UNKNOWN, self::TARGET_FOLLOWER, self::TARGET_ANSWER, self::TARGET_GLOBAL]))) {
$reception_types[$uid] = self::TARGET_BCC;
+ $owner = User::getOwnerDataById($uid);
+ if (!empty($owner['url'])) {
+ $urls['as:bcc'][] = $owner['url'];
+ }
}
}
$object_data['object_type'] = $object_type;
}
+ foreach (['as:to', 'as:cc', 'as:bto', 'as:bcc'] as $element) {
+ if ((empty($object_data['receiver_urls'][$element]) || in_array($element, ['as:bto', 'as:bcc'])) && !empty($urls[$element])) {
+ $object_data['receiver_urls'][$element] = array_unique(array_merge($object_data['receiver_urls'][$element] ?? [], $urls[$element]));
+ }
+ }
+
$object_data['type'] = $type;
$object_data['actor'] = $actor;
$object_data['item_receiver'] = $receivers;
if (!empty($activity['thread-completion'])) {
$object_data['thread-completion'] = $activity['thread-completion'];
}
+
+ if (!empty($activity['completion-mode'])) {
+ $object_data['completion-mode'] = $activity['completion-mode'];
+ }
+
if (!empty($activity['thread-children-type'])) {
$object_data['thread-children-type'] = $activity['thread-children-type'];
}
case 'as:Announce':
if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
$object_data['thread-completion'] = Contact::getIdForURL($actor);
+ $object_data['completion-mode'] = self::COMPLETION_ANNOUCE;
$item = ActivityPub\Processor::createItem($object_data);
if (empty($item)) {
return $uid;
}
+ public static function getReceiverURL($activity)
+ {
+ $urls = [];
+
+ foreach (['as:to', 'as:cc', 'as:bto', 'as:bcc'] as $element) {
+ $receiver_list = JsonLD::fetchElementArray($activity, $element, '@id');
+ if (empty($receiver_list)) {
+ continue;
+ }
+
+ foreach ($receiver_list as $receiver) {
+ if ($receiver == self::PUBLIC_COLLECTION) {
+ $receiver = ActivityPub::PUBLIC_COLLECTION;
+ }
+ $urls[$element][] = $receiver;
+ }
+ }
+
+ return $urls;
+ }
+
/**
* Fetch the receiver list from an activity array
*
$reception_types[$data['uid']] = $data['type'] ?? 0;
}
- $object_data['receiver'] = $receivers;
+ $object_data['receiver_urls'] = self::getReceiverURL($object);
+ $object_data['receiver'] = $receivers;
$object_data['reception_type'] = $reception_types;
$object_data['unlisted'] = in_array(-1, $object_data['receiver']);