diff --git a/plugins/ActivityPub/ActivityPubPlugin.php b/plugins/ActivityPub/ActivityPubPlugin.php index 1fee38f057..37d2da8a4d 100644 --- a/plugins/ActivityPub/ActivityPubPlugin.php +++ b/plugins/ActivityPub/ActivityPubPlugin.php @@ -934,8 +934,9 @@ class ActivityPubPlugin extends Plugin */ public function onEndDeleteUser(Action $action, User $user): void { - $postman = new Activitypub_postman($user->getProfile()); - $postman->delete_profile(); + $deleted_profile = $user->getProfile(); + $postman = new Activitypub_postman($deleted_profile); + $postman->delete_profile($deleted_profile); } /** diff --git a/plugins/ActivityPub/lib/models/Activitypub_delete.php b/plugins/ActivityPub/lib/models/Activitypub_delete.php index 0d19fcc6fa..741740cdc2 100644 --- a/plugins/ActivityPub/lib/models/Activitypub_delete.php +++ b/plugins/ActivityPub/lib/models/Activitypub_delete.php @@ -27,7 +27,7 @@ defined('GNUSOCIAL') || die(); /** - * ActivityPub error representation + * ActivityPub delete representation * * @category Plugin * @package GNUsocial @@ -37,15 +37,29 @@ defined('GNUSOCIAL') || die(); class Activitypub_delete { /** - * Generates an ActivityPub representation of a Delete + * Generates an ActivityStreams 2.0 representation of a Delete * - * @param Notice $notice + * @param Notice $object * @return array pretty array to be used in a response * @author Diogo Cordeiro */ - public static function delete_to_array(Notice $notice): array + public static function delete_to_array($object): array { - return Activitypub_notice::notice_to_array($notice); + if ($object instanceof Notice) { + return Activitypub_notice::notice_to_array($object); + } else if ($object instanceof Profile) { + $actor_uri = $object->getUri(); + return [ + '@context' => 'https://www.w3.org/ns/activitystreams', + 'id' => $actor_uri . '#delete', + 'type' => 'Delete', + 'to' => ['https://www.w3.org/ns/activitystreams#Public'], + 'actor' => $actor_uri, + 'object' => $object + ]; + } else { + throw new InvalidArgumentException(); + } } /** diff --git a/plugins/ActivityPub/lib/postman.php b/plugins/ActivityPub/lib/postman.php index 5d7cdeeeeb..4183e568fa 100644 --- a/plugins/ActivityPub/lib/postman.php +++ b/plugins/ActivityPub/lib/postman.php @@ -408,22 +408,20 @@ class Activitypub_postman /** * Send a Delete notification to remote followers of some deleted profile * - * @param Notice $notice + * @param Profile $deleted_profile * @throws HTTP_Request2_Exception - * @throws InvalidUrlException - * @throws Exception * @author Bruno Casteleiro */ - public function delete_profile() + public function delete_profile(Profile $deleted_profile) { - $data = Activitypub_delete::delete_to_array($this->actor_uri, $this->actor_uri); + $data = Activitypub_delete::delete_to_array($deleted_profile); $data = json_encode($data, JSON_UNESCAPED_SLASHES); $errors = []; foreach ($this->to_inbox() as $inbox) { $res = $this->send($data, $inbox); - // accummulate errors for later use, if needed + // accumulate errors for later use, if needed if (!($res->getStatus() == 200 || $res->getStatus() == 202 || $res->getStatus() == 409)) { $res_body = json_decode($res->getBody(), true); $errors[] = isset($res_body['error']) ?