From 2101250eaaef6cfce8b4880f8213853d19956223 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Tue, 19 May 2015 11:01:11 +0930 Subject: [PATCH] Only notify when a post is created, not edited --- .../Handlers/PostMentionsMetadataUpdater.php | 18 ++++++++++-------- .../Handlers/UserMentionsMetadataUpdater.php | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) 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; } }