From 1a99762699420de0413ad1546e2f788e4e744e73 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sat, 1 Jan 2022 09:34:31 +0000 Subject: [PATCH] [COMPONENT][Posting][Notification] Move group inbox message creation to Notification component --- components/Notification/Notification.php | 5 +++++ components/Posting/Posting.php | 17 ++--------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/components/Notification/Notification.php b/components/Notification/Notification.php index d341dac36b..3625b30282 100644 --- a/components/Notification/Notification.php +++ b/components/Notification/Notification.php @@ -32,6 +32,7 @@ use App\Entity\Activity; use App\Entity\Actor; use App\Entity\LocalUser; use Component\FreeNetwork\FreeNetwork; +use Component\Group\Entity\GroupInbox; use Component\Notification\Controller\Feed; class Notification extends Component @@ -76,6 +77,10 @@ class Notification extends Component if ($target->getIsLocal()) { if ($target->isGroup()) { // FIXME: Make sure we check (for both local and remote) users are in the groups they send to! + DB::persist(GroupInbox::create([ + 'group_id' => $target->getId(), + 'activity_id' => $activity->getId(), + ])); } else { if ($target->hasBlocked($activity->getActor())) { Log::info("Not saving reply to actor {$target->getId()} from sender {$sender->getId()} because of a block."); diff --git a/components/Posting/Posting.php b/components/Posting/Posting.php index de1072e473..0c88bf6bc9 100644 --- a/components/Posting/Posting.php +++ b/components/Posting/Posting.php @@ -46,7 +46,6 @@ use App\Util\Formatting; use Component\Attachment\Entity\ActorToAttachment; use Component\Attachment\Entity\AttachmentToNote; use Component\Conversation\Conversation; -use Component\Group\Entity\GroupInbox; use Component\Group\Entity\LocalGroup; use Component\Language\Entity\Language; use Functional as F; @@ -267,24 +266,12 @@ class Posting extends Component } } - $mentioned = []; - foreach (F\unique(F\flat_map($mentions, fn (array $m) => $m['mentioned'] ?? []), fn (Actor|null $a) => $a?->getId()) as $m) { - if (!\is_null($m)) { - $mentioned[] = $m->getId(); - - if ($m->isGroup()) { - DB::persist(GroupInbox::create([ - 'group_id' => $m->getId(), - 'activity_id' => $activity->getId(), - ])); - } - } - } + $mention_ids = F\unique(F\flat_map($mentions, fn (array $m) => F\map($m['mentioned'] ?? [], fn (Actor $a) => $a->getId()))); DB::flush(); if ($notify) { - Event::handle('NewNotification', [$actor, $activity, ['object' => $mentioned], _m('{nickname} created a note {note_id}.', ['nickname' => $actor->getNickname(), 'note_id' => $activity->getObjectId()])]); + Event::handle('NewNotification', [$actor, $activity, ['object' => $mention_ids], _m('{nickname} created a note {note_id}.', ['nickname' => $actor->getNickname(), 'note_id' => $activity->getObjectId()])]); } return $note;