]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Receiver.php
Merge branch 'develop' of github.com:annando/friendica into develop
[friendica.git] / src / Protocol / ActivityPub / Receiver.php
index 003cae0c9f9a444a3aabd85221538c032963f964..98d40137a9f8a1179eeea2d8260ed890e5ee8bb5 100644 (file)
@@ -68,6 +68,12 @@ class Receiver
        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
         *
@@ -190,7 +196,7 @@ class Receiver
                        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;
@@ -297,12 +303,18 @@ class Receiver
                        $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'];
+                               }
                        }
                }
 
@@ -408,6 +420,12 @@ class Receiver
                        $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;
@@ -517,6 +535,11 @@ class Receiver
                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'];
                }
@@ -543,6 +566,7 @@ class Receiver
                        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)) {
@@ -679,6 +703,27 @@ class Receiver
                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
         *
@@ -1508,7 +1553,8 @@ class Receiver
                        $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']);