[PLUGIN][DeleteNote] Support ActivityPub
This commit is contained in:
@@ -32,6 +32,8 @@ use App\Entity\Actor;
|
||||
use App\Entity\Note;
|
||||
use App\Util\Common;
|
||||
use App\Util\Exception\ClientException;
|
||||
use DateTime;
|
||||
use Plugin\ActivityPub\ActivityPub;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
@@ -62,12 +64,14 @@ class DeleteNote extends NoteHandlerPlugin
|
||||
return $activity;
|
||||
}
|
||||
|
||||
public static function deleteNote(int $note_id, int $actor_id, string $source = 'web'): ?Activity
|
||||
public static function deleteNote(Note|int $note, Actor|int $actor, string $source = 'web'): ?Activity
|
||||
{
|
||||
$actor = \is_int($actor) ? Actor::getById($actor) : $actor;
|
||||
$note = \is_int($note) ? Note::getById($note) : $note;
|
||||
// Try and find if note was already deleted
|
||||
if (\is_null(DB::findOneBy(Activity::class, ['verb' => 'delete', 'object_type' => 'note', 'object_id' => $note_id], return_null: true))) {
|
||||
if (\is_null(DB::findOneBy(Activity::class, ['verb' => 'delete', 'object_type' => 'note', 'object_id' => $note->getId()], return_null: true))) {
|
||||
// If none found, then undertaker has a job to do
|
||||
return self::undertaker(Actor::getById($actor_id), Note::getById($note_id));
|
||||
return self::undertaker($actor, $note);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -101,4 +105,46 @@ class DeleteNote extends NoteHandlerPlugin
|
||||
|
||||
return Event::next;
|
||||
}
|
||||
|
||||
// ActivityPub
|
||||
|
||||
private function activitypub_handler(Actor $actor, \ActivityPhp\Type\AbstractObject $type_activity, mixed $type_object, ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act): bool
|
||||
{
|
||||
if ($type_activity->get('type') !== 'Delete'
|
||||
|| !($type_object instanceof Note)) {
|
||||
return Event::next;
|
||||
}
|
||||
|
||||
$activity = self::deleteNote($type_object, $actor, source: 'ActivityPub');
|
||||
if (!\is_null($activity)) {
|
||||
// Store ActivityPub Activity
|
||||
$ap_act = \Plugin\ActivityPub\Entity\ActivitypubActivity::create([
|
||||
'activity_id' => $activity->getId(),
|
||||
'activity_uri' => $type_activity->get('id'),
|
||||
'created' => new DateTime($type_activity->get('published') ?? 'now'),
|
||||
'modified' => new DateTime(),
|
||||
]);
|
||||
DB::persist($ap_act);
|
||||
}
|
||||
return Event::stop;
|
||||
}
|
||||
|
||||
public function onNewActivityPubActivity(Actor $actor, \ActivityPhp\Type\AbstractObject $type_activity, \ActivityPhp\Type\AbstractObject $type_object, ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act): bool
|
||||
{
|
||||
return $this->activitypub_handler($actor, $type_activity, $type_object, $ap_act);
|
||||
}
|
||||
|
||||
public function onNewActivityPubActivityWithObject(Actor $actor, \ActivityPhp\Type\AbstractObject $type_activity, mixed $type_object, ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act): bool
|
||||
{
|
||||
return $this->activitypub_handler($actor, $type_activity, $type_object, $ap_act);
|
||||
}
|
||||
|
||||
public function onGSVerbToActivityStreamsTwoActivityType(string $verb, ?string &$gs_verb_to_activity_stream_two_verb): bool
|
||||
{
|
||||
if ($verb === 'delete') {
|
||||
$gs_verb_to_activity_stream_two_verb = 'Delete';
|
||||
return Event::stop;
|
||||
}
|
||||
return Event::next;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user