diff --git a/extensions/mentions/src/Handlers/PostMentionsMetadataUpdater.php b/extensions/mentions/src/Handlers/PostMentionsMetadataUpdater.php index 56ee6e267..a5f738234 100755 --- a/extensions/mentions/src/Handlers/PostMentionsMetadataUpdater.php +++ b/extensions/mentions/src/Handlers/PostMentionsMetadataUpdater.php @@ -30,7 +30,15 @@ class PostMentionsMetadataUpdater public function whenPostWasPosted(PostWasPosted $event) { - $this->syncMentions($event->post); + $mentioned = $this->syncMentions($event->post); + + // @todo convert this into a new event (PostWasMentioned) and send + // notification as a handler? + foreach ($mentioned as $post) { + if ($post->user->id !== $reply->user->id) { + $this->notifier->send(new PostMentionedNotification($post, $reply->user, $reply), [$post->user]); + } + } } public function whenPostWasRevised(PostWasRevised $event) @@ -50,12 +58,6 @@ class PostMentionsMetadataUpdater $mentioned = $reply->discussion->posts()->with('user')->whereIn('number', array_filter($matches['number']))->get(); $reply->mentionsPosts()->sync($mentioned->lists('id')); - // @todo convert this into a new event (PostWasMentioned) and send - // notification as a handler? - foreach ($mentioned as $post) { - if ($post->user->id !== $reply->user->id) { - $this->notifier->send(new PostMentionedNotification($post, $reply->user, $reply), [$post->user]); - } - } + return $mentioned; } } diff --git a/extensions/mentions/src/Handlers/UserMentionsMetadataUpdater.php b/extensions/mentions/src/Handlers/UserMentionsMetadataUpdater.php index e191b560c..c137ef959 100755 --- a/extensions/mentions/src/Handlers/UserMentionsMetadataUpdater.php +++ b/extensions/mentions/src/Handlers/UserMentionsMetadataUpdater.php @@ -31,7 +31,15 @@ class UserMentionsMetadataUpdater public function whenPostWasPosted(PostWasPosted $event) { - $this->syncMentions($event->post); + $mentioned = $this->syncMentions($event->post); + + // @todo convert this into a new event (UserWasMentioned) and send + // notification as a handler? + foreach ($mentioned as $user) { + if ($user->id !== $post->user->id) { + $this->notifier->send(new UserMentionedNotification($post->user, $post), [$user]); + } + } } public function whenPostWasRevised(PostWasRevised $event) @@ -51,12 +59,6 @@ class UserMentionsMetadataUpdater $mentioned = User::whereIn('username', array_filter($matches['username']))->get(); $post->mentionsUsers()->sync($mentioned); - // @todo convert this into a new event (UserWasMentioned) and send - // notification as a handler? - foreach ($mentioned as $user) { - if ($user->id !== $post->user->id) { - $this->notifier->send(new UserMentionedNotification($post->user, $post), [$user]); - } - } + return $mentioned; } }