]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Processor.php
New class for c2s activities
[friendica.git] / src / Protocol / ActivityPub / Processor.php
index d57842c2b226362eae4c16cccc9fa3e4eaf842c2..859e7a24512da57518ccfb70a37f16ed9aefec4d 100644 (file)
@@ -35,6 +35,7 @@ use Friendica\Model\APContact;
 use Friendica\Model\Contact;
 use Friendica\Model\Conversation;
 use Friendica\Model\Event;
+use Friendica\Model\Group;
 use Friendica\Model\GServer;
 use Friendica\Model\Item;
 use Friendica\Model\ItemURI;
@@ -1467,13 +1468,14 @@ class Processor
         * @param array      $child       activity array with the child of this message
         * @param string     $relay_actor Relay actor
         * @param int        $completion  Completion mode, see Receiver::COMPLETION_*
+        * @param int        $uid         User id that is used to fetch the activity
         * @return string fetched message URL
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function fetchMissingActivity(string $url, array $child = [], string $relay_actor = '', int $completion = Receiver::COMPLETION_MANUAL): string
+       public static function fetchMissingActivity(string $url, array $child = [], string $relay_actor = '', int $completion = Receiver::COMPLETION_MANUAL, int $uid = 0): string
        {
-               $object = self::fetchCachedActivity($url, 0);
+               $object = self::fetchCachedActivity($url, $uid);
                if (empty($object)) {
                        return '';
                }
@@ -1536,17 +1538,21 @@ class Processor
 
                Contact::updateByUrlIfNeeded($actor);
 
-               if (!empty($relay_actor)) {
-                       $ldactivity['thread-completion'] = $ldactivity['from-relay'] = Contact::getIdForURL($relay_actor);
-                       $ldactivity['completion-mode']   = Receiver::COMPLETION_RELAY;
-               } elseif (!empty($child['thread-completion'])) {
+               if (!empty($child['thread-completion'])) {
                        $ldactivity['thread-completion'] = $child['thread-completion'];
                        $ldactivity['completion-mode']   = $child['completion-mode'] ?? Receiver::COMPLETION_NONE;
                } else {
-                       $ldactivity['thread-completion'] = Contact::getIdForURL($actor);
+                       $ldactivity['thread-completion'] = Contact::getIdForURL($relay_actor ?: $actor);
                        $ldactivity['completion-mode']   = $completion;
                }
 
+               if ($completion == Receiver::COMPLETION_RELAY) {
+                       $ldactivity['from-relay'] = $ldactivity['thread-completion'];
+                       if (!self::acceptIncomingMessage($ldactivity, $object['id'])) {
+                               return '';
+                       }
+               }
+
                if (!empty($child['thread-children-type'])) {
                        $ldactivity['thread-children-type'] = $child['thread-children-type'];
                } elseif (!empty($child['type'])) {
@@ -1555,13 +1561,9 @@ class Processor
                        $ldactivity['thread-children-type'] = 'as:Create';
                }
 
-               if (!empty($relay_actor) && !self::acceptIncomingMessage($ldactivity, $object['id'])) {
-                       return '';
-               }
-
                if (($completion == Receiver::COMPLETION_RELAY) && Queue::exists($url, 'as:Create')) {
                        Logger::notice('Activity has already been queued.', ['url' => $url, 'object' => $activity['id']]);
-               } elseif (ActivityPub\Receiver::processActivity($ldactivity, json_encode($activity), 0, true, false, $signer, '', $completion)) {
+               } elseif (ActivityPub\Receiver::processActivity($ldactivity, json_encode($activity), $uid, true, false, $signer, '', $completion)) {
                        Logger::notice('Activity had been fetched and processed.', ['url' => $url, 'entry' => $child['entry-id'] ?? 0, 'completion' => $completion, 'object' => $activity['id']]);
                } else {
                        Logger::notice('Activity had been fetched and will be processed later.', ['url' => $url, 'entry' => $child['entry-id'] ?? 0, 'completion' => $completion, 'object' => $activity['id']]);