]> git.mxchange.org Git - friendica.git/commitdiff
Account deletion could work now.
authorMichael <heluecht@pirati.ca>
Mon, 1 Oct 2018 19:22:13 +0000 (19:22 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 1 Oct 2018 19:22:13 +0000 (19:22 +0000)
src/Protocol/ActivityPub.php
src/Worker/APDelivery.php
src/Worker/Notifier.php

index 4c77c8dff92a43dc76da30a2f81c985e8ed11635..b5cd102a51d4ac1e74295edd915f3020b2d4d875 100644 (file)
@@ -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:
@@ -441,9 +440,13 @@ class ActivityPub
        {
                $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;
@@ -731,6 +734,32 @@ class ActivityPub
                return $data;
        }
 
+       /**
+        * @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
         *
index eb0b3d9b15625f303dde8146efdf55f05724c9da..22b8c8f0ffd865560ab8fb827f091a3369950399 100644 (file)
@@ -18,6 +18,8 @@ class APDelivery extends BaseObject
                if ($cmd == Delivery::MAIL) {
                } elseif ($cmd == Delivery::SUGGESTION) {
                } elseif ($cmd == Delivery::RELOCATION) {
+               } elseif ($cmd == Delivery::REMOVAL) {
+                       ActivityPub::transmitProfileDeletion($uid, $inbox);
                } elseif ($cmd == Delivery::PROFILEUPDATE) {
                        ActivityPub::transmitProfileUpdate($uid, $inbox);
                } else {
index b457b7800851177c4254f505e4ef515c5c290992..3ab238422abad5f6ef20384f9f5c40451cb4151f 100644 (file)
@@ -99,6 +99,14 @@ class Notifier
                        foreach ($r as $contact) {
                                Contact::terminateFriendship($user, $contact, true);
                        }
+
+                       $inboxes = ActivityPub::fetchTargetInboxesforUser(0);
+                       foreach ($inboxes as $inbox) {
+                               logger('Account removal for user ' . $uid . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG);
+                               Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
+                                       'APDelivery', Delivery::REMOVAL, '', $inbox, $uid);
+                       }
+
                        return;
                } elseif ($cmd == Delivery::RELOCATION) {
                        $normal_mode = false;