Notification API tweaks

This commit is contained in:
Toby Zerner 2015-06-26 12:18:53 +09:30
parent 8cc47c77de
commit efbe46f7a9
2 changed files with 22 additions and 7 deletions

View File

@ -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());
}
);
}

View File

@ -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
];
}
}