[PLUGIN][ActivityPub] Support federation of Tombstones

This commit is contained in:
Diogo Peralta Cordeiro 2021-12-28 16:44:38 +00:00
parent 9cda64f275
commit 1d1d169a5c
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
3 changed files with 21 additions and 7 deletions

View File

@ -268,13 +268,13 @@ class ActivityPub extends Plugin
}
}
} catch (Exception $e) {
Log::error('ActivityPub @ freeNetworkDistribute: ' . $e->getMessage());
Log::error('ActivityPub @ freeNetworkDistribute: ' . $e->getMessage(), [$e]);
//$to_failed[$inbox] = $activity;
}
}
if (!empty($errors)) {
Log::error(sizeof($errors) . ' instance/s failed to handle the delete_profile activity!');
Log::error(sizeof($errors) . ' instance/s failed to handle our activity!');
return false;
}

View File

@ -124,9 +124,9 @@ abstract class Model
public static function toJson(mixed $object, ?int $options = null): string
{
switch ($object::class) {
case 'App\Entity\Activity':
case \App\Entity\Activity::class:
return Activity::toJson($object, $options);
case 'App\Entity\Note':
case \App\Entity\Note::class:
return Note::toJson($object, $options);
default:
$type = self::jsonToType($object);

View File

@ -40,6 +40,7 @@ use App\Core\Router\Router;
use App\Entity\Activity as GSActivity;
use App\Util\Exception\ClientException;
use App\Util\Exception\NoSuchActorException;
use App\Util\Exception\NotFoundException;
use DateTime;
use DateTimeInterface;
use Exception;
@ -165,11 +166,24 @@ class Activity extends Model
'to' => ['https://www.w3.org/ns/activitystreams#Public'], // TODO: implement proper scope address
'cc' => ['https://www.w3.org/ns/activitystreams#Public'],
];
$attr['object'] = ($attr['type'] === 'Create') ? self::jsonToType(Model::toJson($object->getObject())) : ActivityPub::getUriByObject($object->getObject());
try {
$object = $object->getObject(); // Throws NotFoundException
$attr['object'] = ($attr['type'] === 'Create') ? self::jsonToType(Model::toJson($object)) : ActivityPub::getUriByObject($object);
} catch (NotFoundException) {
// It seems this object was deleted, refer to it as a Tombstone
$uri = match ($object->getObjectType()) {
'note' => Router::url('note_view', ['id' => $object->getObjectId()], type: Router::ABSOLUTE_URL),
'actor' => Router::url('actor_view_id', ['id' => $object->getObjectId()], type: Router::ABSOLUTE_URL),
default => throw new \App\Util\Exception\NotImplementedException(),
};
$attr['object'] = Type::create('Tombstone', [
'id' => $uri,
]);
}
if (!\is_string($attr['object'])) {
$attr['to'] = array_unique(array_merge($attr['to'], $attr['object']->get('to')));
$attr['cc'] = array_unique(array_merge($attr['cc'], $attr['object']->get('cc')));
$attr['to'] = array_unique(array_merge($attr['to'], $attr['object']->get('to') ?? []));
$attr['cc'] = array_unique(array_merge($attr['cc'], $attr['object']->get('cc') ?? []));
}
$type = self::jsonToType($attr);