]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Receiver.php
New post class in protocol and worker classes
[friendica.git] / src / Protocol / ActivityPub / Receiver.php
index 3c0f4862e6d212475771012f3a4d62ce23b30847..f48135f77272b0ee9f1d1f286d64e491b4068b93 100644 (file)
@@ -30,6 +30,7 @@ use Friendica\Core\Protocol;
 use Friendica\Model\Contact;
 use Friendica\Model\APContact;
 use Friendica\Model\Item;
+use Friendica\Model\Post;
 use Friendica\Model\User;
 use Friendica\Protocol\Activity;
 use Friendica\Protocol\ActivityPub;
@@ -99,9 +100,13 @@ class Receiver
                $actor = JsonLD::fetchElement($ldactivity, 'as:actor', '@id');
 
                $apcontact = APContact::getByURL($actor);
-               if (!empty($apcontact) && ($apcontact['type'] == 'Application') && ($apcontact['nick'] == 'relay')) {
+               if (empty($apcontact)) {
+                       Logger::notice('Unable to retrieve AP contact for actor', ['actor' => $actor]);
+               } elseif ($apcontact['type'] == 'Application' && $apcontact['nick'] == 'relay') {
                        self::processRelayPost($ldactivity, $actor);
                        return;
+               } else {
+                       APContact::unmarkForArchival($apcontact);
                }
 
                $http_signer = HTTPSignature::getSigner($body, $header);
@@ -226,13 +231,14 @@ class Receiver
                        }
                }
 
-               if (Item::exists(['uri' => $object_id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]])) {
+               if (Post::exists(['uri' => $object_id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]])) {
                        // We just assume "note" since it doesn't make a difference for the further processing
                        return 'as:Note';
                }
 
                $profile = APContact::getByURL($object_id);
                if (!empty($profile['type'])) {
+                       APContact::unmarkForArchival($profile);
                        return 'as:' . $profile['type'];
                }
 
@@ -353,6 +359,7 @@ class Receiver
                        $object_data['author'] = JsonLD::fetchElement($activity, 'as:actor', '@id');
                        $object_data['object_id'] = $object_id;
                        $object_data['object_type'] = ''; // Since we don't fetch the object, we don't know the type
+                       $object_data['push'] = $push;
                } elseif (in_array($type, ['as:Add'])) {
                        $object_data = [];
                        $object_data['id'] = JsonLD::fetchElement($activity, '@id');
@@ -360,6 +367,7 @@ class Receiver
                        $object_data['object_id'] = JsonLD::fetchElement($activity, 'as:object', '@id');
                        $object_data['object_type'] = JsonLD::fetchElement($activity['as:object'], '@type');
                        $object_data['object_content'] = JsonLD::fetchElement($activity['as:object'], 'as:content', '@type');
+                       $object_data['push'] = $push;
                } else {
                        $object_data = [];
                        $object_data['id'] = JsonLD::fetchElement($activity, '@id');
@@ -367,6 +375,7 @@ class Receiver
                        $object_data['object_actor'] = JsonLD::fetchElement($activity['as:object'], 'as:actor', '@id');
                        $object_data['object_object'] = JsonLD::fetchElement($activity['as:object'], 'as:object');
                        $object_data['object_type'] = JsonLD::fetchElement($activity['as:object'], '@type');
+                       $object_data['push'] = $push;
 
                        // An Undo is done on the object of an object, so we need that type as well
                        if (($type == 'as:Undo') && !empty($object_data['object_object'])) {
@@ -642,10 +651,11 @@ class Receiver
                }
 
                if (!empty($reply)) {
-                       $parents = Item::select(['uid'], ['uri' => $reply]);
-                       while ($parent = Item::fetch($parents)) {
+                       $parents = Post::select(['uid'], ['uri' => $reply]);
+                       while ($parent = Post::fetch($parents)) {
                                $receivers[$parent['uid']] = ['uid' => $parent['uid'], 'type' => self::TARGET_ANSWER];
                        }
+                       DBA::close($parents);
                }
 
                if (!empty($actor)) {
@@ -920,7 +930,7 @@ class Receiver
                        } else {
                                Logger::log('Empty content for ' . $object_id . ', check if content is available locally.', Logger::DEBUG);
 
-                               $item = Item::selectFirst([], ['uri' => $object_id]);
+                               $item = Post::selectFirst([], ['uri' => $object_id]);
                                if (!DBA::isResult($item)) {
                                        Logger::log('Object with url ' . $object_id . ' was not found locally.', Logger::DEBUG);
                                        return false;