[ActivityPub] Re-implement Delete Actor

This commit is contained in:
Diogo Peralta Cordeiro 2021-02-21 14:59:36 +00:00
parent 4f0ddc85d3
commit b1e6b00545
3 changed files with 26 additions and 13 deletions

View File

@ -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);
}
/**

View File

@ -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 <diogo@fc.up.pt>
*/
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();
}
}
/**

View File

@ -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 <brunoccast@fc.up.pt>
*/
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']) ?