forked from GNUsocial/gnu-social
[PLUGIN][ActivityPub] Only store a new object if there were no previous activities with it before
This commit is contained in:
parent
5196b669b9
commit
330e09f2d3
@ -81,11 +81,15 @@ 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.');
|
||||||
}
|
}
|
||||||
|
// Store Object if new
|
||||||
|
$ap_act = ActivitypubActivity::getWithPK(['object_uri' => $type_activity->get('object')->get('id')]);
|
||||||
|
if (!is_null($ap_act)) {
|
||||||
|
$obj = $ap_act->getActivity()->getObject();
|
||||||
|
} else {
|
||||||
|
$obj = null;
|
||||||
switch ($type_activity->get('object')->get('type')) {
|
switch ($type_activity->get('object')->get('type')) {
|
||||||
case 'Note':
|
case 'Note':
|
||||||
$obj = Note::fromJson($type_activity->get('object'), ['source' => $source, 'actor_uri' => $type_activity->get('actor'), 'actor_id' => $actor->getId()]);
|
$obj = Note::fromJson($type_activity->get('object'), ['source' => $source, 'actor_uri' => $type_activity->get('actor'), 'actor_id' => $actor->getId()]);
|
||||||
@ -97,6 +101,7 @@ class Activity extends Model
|
|||||||
break;
|
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(),
|
||||||
|
Loading…
Reference in New Issue
Block a user