[PLUGINS][Favourite][RepeatNote][DeleteNote][WebMonetization] Make use of 'activitypub_handler' more readable

This commit is contained in:
Hugo Sales 2022-03-10 00:40:54 +00:00
parent 9a9eed1457
commit 0ce5eba355
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
4 changed files with 26 additions and 24 deletions

View File

@ -200,6 +200,7 @@ class DeleteNote extends NoteHandlerPlugin
{
if ($type_activity->get('type') !== 'Delete'
|| !($type_object instanceof Note)) {
// Don't care about AbstractObject because we only want to delete objects we already have
return Event::next;
}

View File

@ -280,6 +280,7 @@ class Favourite extends NoteHandlerPlugin
if (!\in_array($type_activity->get('type'), ['Like', 'Undo'])) {
return Event::next;
}
if ($type_activity->get('type') === 'Like') { // Favourite
if ($type_object instanceof \ActivityPhp\Type\AbstractObject) {
if ($type_object->get('type') === 'Note' || $type_object->get('type') === 'ChatMessage' || $type_object->get('type') === 'Page') {
@ -293,29 +294,30 @@ class Favourite extends NoteHandlerPlugin
} else {
return Event::next;
}
} elseif ($type_object instanceof \ActivityPhp\Type\AbstractObject) {
$ap_prev_favourite_act = \Plugin\ActivityPub\Util\Model\Activity::fromJson($type_object);
$prev_favourite_act = $ap_prev_favourite_act->getActivity();
if ($prev_favourite_act->getVerb() === 'favourite' && $prev_favourite_act->getObjectType() === 'note') {
$note_id = $prev_favourite_act->getObjectId();
} else {
return Event::next;
}
} elseif ($type_object instanceof Activity) {
if ($type_object->getVerb() === 'favourite' && $type_object->getObjectType() === 'note') {
$note_id = $type_object->getObjectId();
$activity = self::favourNote($note_id, $actor->getId(), source: 'ActivityPub');
} elseif ($type_activity->get('type') === 'Undo') {
if ($type_object instanceof \ActivityPhp\Type\AbstractObject) {
$ap_prev_favourite_act = \Plugin\ActivityPub\Util\Model\Activity::fromJson($type_object);
$prev_favourite_act = $ap_prev_favourite_act->getActivity();
if ($prev_favourite_act->getVerb() === 'favourite' && $prev_favourite_act->getObjectType() === 'note') {
$note_id = $prev_favourite_act->getObjectId();
} else {
return Event::next;
}
} elseif ($type_object instanceof Activity) {
if ($type_object->getVerb() === 'favourite' && $type_object->getObjectType() === 'note') {
$note_id = $type_object->getObjectId();
} else {
return Event::next;
}
} else {
return Event::next;
}
$activity = self::unfavourNote($note_id, $actor->getId(), source: 'ActivityPub');
} else {
return Event::next;
}
if ($type_activity->get('type') === 'Like') {
$activity = self::favourNote($note_id, $actor->getId(), source: 'ActivityPub');
} else {
$activity = self::unfavourNote($note_id, $actor->getId(), source: 'ActivityPub');
}
if (!\is_null($activity)) {
// Store ActivityPub Activity
$ap_act = \Plugin\ActivityPub\Entity\ActivitypubActivity::create([

View File

@ -376,7 +376,8 @@ class RepeatNote extends NoteHandlerPlugin
} else {
return Event::next;
}
} else { // Undo Repeat
$activity = self::repeatNote($note ?? Note::getById($note_id), $actor->getId(), source: 'ActivityPub');
} elseif ($type_activity->get('type') === 'Undo') { // Undo Repeat
if ($type_object instanceof \ActivityPhp\Type\AbstractObject) {
$ap_prev_repeat_act = \Plugin\ActivityPub\Util\Model\Activity::fromJson($type_object);
$prev_repeat_act = $ap_prev_repeat_act->getActivity();
@ -394,13 +395,11 @@ class RepeatNote extends NoteHandlerPlugin
} else {
return Event::next;
}
$activity = self::unrepeatNote($note_id, $actor->getId(), source: 'ActivityPub');
} else {
return Event::next;
}
if ($type_activity->get('type') === 'Announce') {
$activity = self::repeatNote($note ?? Note::getById($note_id), $actor->getId(), source: 'ActivityPub');
} else {
$activity = self::unrepeatNote($note_id, $actor->getId(), source: 'ActivityPub');
}
if (!\is_null($activity)) {
// Store ActivityPub Activity
$ap_act = \Plugin\ActivityPub\Entity\ActivitypubActivity::create([

View File

@ -66,7 +66,7 @@ class WebMonetization extends Plugin
if ($vars['path'] === 'settings') {
$is_self = true;
} elseif ($vars['path'] === 'actor_view_nickname') {
} elseif ($vars['path'] === 'actor_view_nickname') {
$is_self = $request->attributes->get('nickname') === $user->getNickname();
if (!$is_self) {
$receiver_id = DB::findOneBy(LocalUser::class, [
@ -258,7 +258,7 @@ class WebMonetization extends Plugin
$wallet = DB::findOneBy(Wallet::class, ['actor_id' => $actor->getId()], return_null: true);
if (!\is_null($address = $wallet?->getAddress())) {
$type->set('gs:webmonetizationWallet', $address);
$type->set('webmonetizationWallet', $address);
}
}
return Event::next;