[PLUGIN][ActivityPub] Only store a new object if there were no previous activities with it before

This commit is contained in:
Diogo Peralta Cordeiro 2021-12-05 21:09:30 +00:00
parent 5196b669b9
commit 330e09f2d3
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
1 changed files with 17 additions and 12 deletions

View File

@ -81,22 +81,27 @@ class Activity extends Model
$ap_act = ActivitypubActivity::getWithPK(['activity_uri' => $type_activity->get('id')]); $ap_act = ActivitypubActivity::getWithPK(['activity_uri' => $type_activity->get('id')]);
if (is_null($ap_act)) { if (is_null($ap_act)) {
$actor = ActivityPub::getActorByUri($type_activity->get('actor')); $actor = ActivityPub::getActorByUri($type_activity->get('actor'));
// Store Object
$obj = null;
if (!$type_activity->has('object') || !$type_activity->get('object')->has('type')) { if (!$type_activity->has('object') || !$type_activity->get('object')->has('type')) {
throw new InvalidArgumentException('Activity Object or Activity Object Type is missing.'); throw new InvalidArgumentException('Activity Object or Activity Object Type is missing.');
} }
switch ($type_activity->get('object')->get('type')) { // Store Object if new
case 'Note': $ap_act = ActivitypubActivity::getWithPK(['object_uri' => $type_activity->get('object')->get('id')]);
$obj = Note::fromJson($type_activity->get('object'), ['source' => $source, 'actor_uri' => $type_activity->get('actor'), 'actor_id' => $actor->getId()]); if (!is_null($ap_act)) {
break; $obj = $ap_act->getActivity()->getObject();
default: } else {
if (!Event::handle('ActivityPubObject', [$type_activity->get('object')->get('type'), $type_activity->get('object'), &$obj])) { $obj = null;
throw new ClientException('Unsupported Object type.'); switch ($type_activity->get('object')->get('type')) {
} case 'Note':
break; $obj = Note::fromJson($type_activity->get('object'), ['source' => $source, 'actor_uri' => $type_activity->get('actor'), 'actor_id' => $actor->getId()]);
break;
default:
if (!Event::handle('ActivityPubObject', [$type_activity->get('object')->get('type'), $type_activity->get('object'), &$obj])) {
throw new ClientException('Unsupported Object type.');
}
break;
}
DB::persist($obj);
} }
DB::persist($obj);
// Store Activity // Store Activity
$act = GSActivity::create([ $act = GSActivity::create([
'actor_id' => $actor->getId(), 'actor_id' => $actor->getId(),