From 0ce5eba355b5856fbef6591335bf491bc8dacf0f Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Thu, 10 Mar 2022 00:40:54 +0000 Subject: [PATCH] [PLUGINS][Favourite][RepeatNote][DeleteNote][WebMonetization] Make use of 'activitypub_handler' more readable --- plugins/DeleteNote/DeleteNote.php | 1 + plugins/Favourite/Favourite.php | 34 +++++++++++---------- plugins/RepeatNote/RepeatNote.php | 11 +++---- plugins/WebMonetization/WebMonetization.php | 4 +-- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/plugins/DeleteNote/DeleteNote.php b/plugins/DeleteNote/DeleteNote.php index 210348d74b..775822bcda 100644 --- a/plugins/DeleteNote/DeleteNote.php +++ b/plugins/DeleteNote/DeleteNote.php @@ -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; } diff --git a/plugins/Favourite/Favourite.php b/plugins/Favourite/Favourite.php index 9d0cfc2e64..e9eb6801a3 100644 --- a/plugins/Favourite/Favourite.php +++ b/plugins/Favourite/Favourite.php @@ -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([ diff --git a/plugins/RepeatNote/RepeatNote.php b/plugins/RepeatNote/RepeatNote.php index f5a6808733..5ced1f13f5 100644 --- a/plugins/RepeatNote/RepeatNote.php +++ b/plugins/RepeatNote/RepeatNote.php @@ -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([ diff --git a/plugins/WebMonetization/WebMonetization.php b/plugins/WebMonetization/WebMonetization.php index 1f67370452..bd396b44de 100644 --- a/plugins/WebMonetization/WebMonetization.php +++ b/plugins/WebMonetization/WebMonetization.php @@ -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;