[PLUGIN][ActivityPub] Simplify DB usage

This commit is contained in:
2022-02-18 17:48:06 +00:00
parent 9523927b8e
commit 51cccd0155
14 changed files with 122 additions and 116 deletions

View File

@@ -110,11 +110,6 @@ class RepeatNote extends NoteHandlerPlugin
]);
DB::persist($repeat_activity);
// Flush before notification
DB::flush();
Event::handle('NewNotification', [$actor = Actor::getById($actor_id), $repeat_activity, [], _m('{nickname} repeated note {note_id}.', ['{nickname}' => $actor->getNickname(), '{note_id}' => $repeat_activity->getObjectId()])]);
return $repeat_activity;
}
@@ -165,8 +160,6 @@ class RepeatNote extends NoteHandlerPlugin
]);
DB::persist($undo_repeat_activity);
Event::handle('NewNotification', [$actor = Actor::getById($actor_id), $undo_repeat_activity, [], _m('{nickname} unrepeated note {note_id}.', ['{nickname}' => $actor->getNickname(), '{note_id}' => $note_id])]);
return $undo_repeat_activity;
} else {
// Either was undoed already
@@ -397,9 +390,15 @@ class RepeatNote extends NoteHandlerPlugin
}
if ($type_activity->get('type') === 'Announce') {
$activity = self::repeatNote($note ?? Note::getById($note_id), $actor->getId(), source: 'ActivityPub');
if (!\is_null($activity = self::repeatNote($note ?? Note::getById($note_id), $actor->getId(), source: 'ActivityPub'))) {
DB::flush();
Event::handle('NewNotification', [$actor, $activity, [], _m('{nickname} repeated note {note_id}.', ['{nickname}' => $actor->getNickname(), '{note_id}' => $activity->getObjectId()])]);
}
} else {
$activity = self::unrepeatNote($note_id, $actor->getId(), source: 'ActivityPub');
if (!\is_null($activity = self::unrepeatNote($note_id, $actor->getId(), source: 'ActivityPub'))) {
DB::flush();
Event::handle('NewNotification', [$actor, $activity, [], _m('{nickname} unrepeated note {note_id}.', ['{nickname}' => $actor->getNickname(), '{note_id}' => $note_id])]);
}
}
if (!\is_null($activity)) {
// Store ActivityPub Activity