diff --git a/plugins/ActivityPub/Controller/Inbox.php b/plugins/ActivityPub/Controller/Inbox.php index 55ab5c8a07..34eed955f0 100644 --- a/plugins/ActivityPub/Controller/Inbox.php +++ b/plugins/ActivityPub/Controller/Inbox.php @@ -178,8 +178,11 @@ class Inbox extends Controller if (!empty($ap_act->_object_mention_ids)) { $already_known_ids = $ap_act->_object_mention_ids; } + DB::flush(); - Event::handle('NewNotification', [$actor, $ap_act->getActivity(), $already_known_ids, _m('{nickname} mentioned you.', ['{nickname}' => $actor->getNickname()])]); + if (Event::handle('ActivityPubNewNotification', [$actor, $ap_act->getActivity(), $already_known_ids, _m('{nickname} mentioned you.', ['{nickname}' => $actor->getNickname()])]) === Event::next) { + Event::handle('NewNotification', [$actor, $ap_act->getActivity(), $already_known_ids, _m('{nickname} mentioned you.', ['{nickname}' => $actor->getNickname()])]); + } dd($ap_act, $act = $ap_act->getActivity(), $act->getActor(), $act->getObject()); diff --git a/plugins/Favourite/Favourite.php b/plugins/Favourite/Favourite.php index 191cfb3c3e..fe3f2187aa 100644 --- a/plugins/Favourite/Favourite.php +++ b/plugins/Favourite/Favourite.php @@ -313,15 +313,9 @@ class Favourite extends NoteHandlerPlugin } if ($type_activity->get('type') === 'Like') { - if (!\is_null($activity = self::favourNote($note_id, $actor->getId(), source: 'ActivityPub'))) { - DB::flush(); - Event::handle('NewNotification', [$actor, $activity, [], _m('{nickname} favoured note {note_id}.', ['{nickname}' => $actor->getNickname(), '{note_id}' => $activity->getObjectId()])]); - } + $activity = self::favourNote($note_id, $actor->getId(), source: 'ActivityPub'); } else { - if (!\is_null($activity = self::unfavourNote($note_id, $actor->getId(), source: 'ActivityPub'))) { - DB::flush(); - Event::handle('NewNotification', [$actor, $activity, [], _m('{nickname} unfavoured note {note_id}.', ['{nickname}' => $actor->getNickname(), '{note_id}' => $activity->getObjectId()])]); - } + $activity = self::unfavourNote($note_id, $actor->getId(), source: 'ActivityPub'); } if (!\is_null($activity)) { // Store ActivityPub Activity @@ -336,6 +330,24 @@ class Favourite extends NoteHandlerPlugin return Event::stop; } + public function onActivityPubNewNotification(Actor $sender, Activity $activity, array $ids_already_known = [], ?string $reason = null): bool + { + switch ($activity->getVerb()) { + case 'favourite': + Event::handle('NewNotification', [$sender, $activity, [], _m('{nickname} favoured note {note_id}.', ['{nickname}' => $sender->getNickname(), '{note_id}' => $activity->getObjectId()])]); + return Event::stop; + case 'undo': + if ($activity->getObjectType() === 'activity') { + $undone_favourite = $activity->getObject(); + if ($undone_favourite->getVerb() === 'favourite') { + Event::handle('NewNotification', [$sender, $activity, [], _m('{nickname} unfavoured note {note_id}.', ['{nickname}' => $sender->getNickname(), '{note_id}' => $activity->getObjectId()])]); + return Event::stop; + } + } + } + return Event::next; + } + /** * Convert an Activity Streams 2.0 Like or Undo Like into the appropriate Favourite and Undo Favourite entities * diff --git a/plugins/RepeatNote/RepeatNote.php b/plugins/RepeatNote/RepeatNote.php index c36650b6e3..f8a72f0464 100644 --- a/plugins/RepeatNote/RepeatNote.php +++ b/plugins/RepeatNote/RepeatNote.php @@ -390,15 +390,9 @@ class RepeatNote extends NoteHandlerPlugin } if ($type_activity->get('type') === 'Announce') { - 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()])]); - } + $activity = self::repeatNote($note ?? Note::getById($note_id), $actor->getId(), source: 'ActivityPub'); } else { - 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])]); - } + $activity = self::unrepeatNote($note_id, $actor->getId(), source: 'ActivityPub'); } if (!\is_null($activity)) { // Store ActivityPub Activity @@ -413,6 +407,24 @@ class RepeatNote extends NoteHandlerPlugin return Event::stop; } + public function onActivityPubNewNotification(Actor $sender, Activity $activity, array $ids_already_known = [], ?string $reason = null): bool + { + switch ($activity->getVerb()) { + case 'repeat': + Event::handle('NewNotification', [$sender, $activity, [], _m('{nickname} repeated note {note_id}.', ['{nickname}' => $sender->getNickname(), '{note_id}' => $activity->getObjectId()])]); + return Event::stop; + case 'undo': + if ($activity->getObjectType() === 'activity') { + $undone_repeat = $activity->getObject(); + if ($undone_repeat->getVerb() === 'repeat') { + Event::handle('NewNotification', [$sender, $activity, [], _m('{nickname} unrepeated note {note_id}.', ['{nickname}' => $sender->getNickname(), '{note_id}' => $undone_repeat->getObjectId()])]); + return Event::stop; + } + } + } + return Event::next; + } + /** * Convert an Activity Streams 2.0 Announce or Undo Announce into the appropriate Repeat and Undo Repeat entities *