From efbe46f7a99d5f2356839e2192e235e5cdf8ded3 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 26 Jun 2015 12:18:53 +0930 Subject: [PATCH] Notification API tweaks --- .../Core/Notifications/NotificationMailer.php | 2 +- .../Core/Notifications/NotificationSyncer.php | 27 ++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/framework/core/src/Core/Notifications/NotificationMailer.php b/framework/core/src/Core/Notifications/NotificationMailer.php index 7c3821522..5b2bf21df 100644 --- a/framework/core/src/Core/Notifications/NotificationMailer.php +++ b/framework/core/src/Core/Notifications/NotificationMailer.php @@ -19,7 +19,7 @@ class NotificationMailer compact('notification', 'user'), function ($message) use ($notification, $user) { $message->to($user->email, $user->username) - ->subject('['.$this->forum->title.'] '.$notification->getEmailSubject()); + ->subject($notification->getEmailSubject()); } ); } diff --git a/framework/core/src/Core/Notifications/NotificationSyncer.php b/framework/core/src/Core/Notifications/NotificationSyncer.php index b9a18f011..2cf670d8f 100644 --- a/framework/core/src/Core/Notifications/NotificationSyncer.php +++ b/framework/core/src/Core/Notifications/NotificationSyncer.php @@ -33,12 +33,7 @@ class NotificationSyncer */ public function sync(NotificationInterface $notification, array $users) { - $attributes = [ - 'type' => $notification::getType(), - 'sender_id' => $notification->getSender()->id, - 'subject_id' => $notification->getSubject()->id, - 'data' => ($data = $notification->getData()) ? json_encode($data) : null - ]; + $attributes = $this->getAttributes($notification); $toDelete = Notification::where($attributes)->get(); $toUndelete = []; @@ -83,6 +78,16 @@ class NotificationSyncer } } + public function delete(NotificationInterface $notification) + { + Notification::where($this->getAttributes($notification))->update(['is_deleted' => true]); + } + + public function restore(NotificationInterface $notification) + { + Notification::where($this->getAttributes($notification))->update(['is_deleted' => false]); + } + public function onePerUser(Closure $callback) { $this->sentTo = []; @@ -92,4 +97,14 @@ class NotificationSyncer $this->onePerUser = false; } + + protected function getAttributes(NotificationInterface $notification) + { + return [ + 'type' => $notification::getType(), + 'sender_id' => $notification->getSender()->id, + 'subject_id' => $notification->getSubject()->id, + 'data' => ($data = $notification->getData()) ? json_encode($data) : null + ]; + } }