]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub.php
Merge pull request #5812 from annando/develop
[friendica.git] / src / Protocol / ActivityPub.php
index 6fdd0795a573c623b816b9f0a3c7db60d3761d88..ef4a48479ea2a4c677704763af81d10272e443a8 100644 (file)
@@ -45,7 +45,7 @@ use Friendica\Core\Config;
  *
  * Receiver:
  * - Update (Image, Video, Article, Note)
+ - Event
* - Event
  * - Undo Announce
  *
  * Check what this is meant to do:
@@ -57,7 +57,6 @@ use Friendica\Core\Config;
  * - Undo Accept (Problem: This could invert a contact accept or an event accept)
  *
  * Transmitter:
- * - Delete (Application, Group, Organization, Person, Service)
  * - Event
  *
  * Complicated:
@@ -437,13 +436,17 @@ class ActivityPub
         *
         * @return array of follower inboxes
         */
-       private static function fetchTargetInboxesforUser($uid)
+       public static function fetchTargetInboxesforUser($uid)
        {
                $inboxes = [];
 
-               $contacts = DBA::select('contact', ['notify', 'batch'], ['uid' => $uid,
-                       'rel' => [Contact::FOLLOWER, Contact::FRIEND], 'network' => Protocol::ACTIVITYPUB,
-                       'archive' => false, 'pending' => false]);
+               $condition = ['uid' => $uid, 'network' => Protocol::ACTIVITYPUB, 'archive' => false, 'pending' => false];
+
+               if (!empty($uid)) {
+                       $condition['rel'] = [Contact::FOLLOWER, Contact::FRIEND];
+               }
+
+               $contacts = DBA::select('contact', ['notify', 'batch'], $condition);
                while ($contact = DBA::fetch($contacts)) {
                        $contact = defaults($contact, 'batch', $contact['notify']);
                        $inboxes[$contact] = $contact;
@@ -660,7 +663,7 @@ class ActivityPub
                } elseif (DBA::isResult($conversation) && !empty($conversation['conversation-uri'])) {
                        $context_uri = $conversation['conversation-uri'];
                } else {
-                       $context_uri = str_replace('/object/', '/context/', $item['parent-uri']);
+                       $context_uri = str_replace('/objects/', '/context/', $item['parent-uri']);
                }
                return $context_uri;
        }
@@ -732,11 +735,38 @@ class ActivityPub
        }
 
        /**
-        * @brief Transmits a profile change to the followers
+        * @brief Transmits a profile deletion to a given inbox
+        *
+        * @param integer $uid User ID
+        * @param string $inbox Target inbox
+        */
+       public static function transmitProfileDeletion($uid, $inbox)
+       {
+               $owner = User::getOwnerDataById($uid);
+               $profile = APContact::getByURL($owner['url']);
+
+               $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
+                       'id' => System::baseUrl() . '/activity/' . System::createGUID(),
+                       'type' => 'Delete',
+                       'actor' => $owner['url'],
+                       'object' => self::profile($uid),
+                       'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
+                       'to' => [self::PUBLIC_COLLECTION],
+                       'cc' => []];
+
+               $signed = LDSignature::sign($data, $owner);
+
+               logger('Deliver profile deletion for user ' . $uid . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG);
+               HTTPSignature::transmit($signed, $inbox, $uid);
+       }
+
+       /**
+        * @brief Transmits a profile change to a given inbox
         *
         * @param integer $uid User ID
+        * @param string $inbox Target inbox
         */
-       public static function transmitProfileUpdate($uid)
+       public static function transmitProfileUpdate($uid, $inbox)
        {
                $owner = User::getOwnerDataById($uid);
                $profile = APContact::getByURL($owner['url']);
@@ -750,17 +780,12 @@ class ActivityPub
                        'to' => [$profile['followers']],
                        'cc' => []];
 
-               logger('Sending profile update to followers for user ' . $uid, LOGGER_DEBUG);
-
                $signed = LDSignature::sign($data, $owner);
 
-               $inboxes = self::fetchTargetInboxesforUser($uid);
-
-               foreach ($inboxes as $inbox) {
-                       logger('Deliver profile update for user ' . $uid . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG);
-                       HTTPSignature::transmit($signed, $inbox, $uid);
-               }
+               logger('Deliver profile update for user ' . $uid . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG);
+               HTTPSignature::transmit($signed, $inbox, $uid);
        }
+
        /**
         * @brief Transmits a given activity to a target
         *
@@ -1403,7 +1428,7 @@ class ActivityPub
         *
         * @return 
         */
-       private static function processObject(&$object)
+       private static function processObject($object)
        {
                if (empty($object['id'])) {
                        return false;