mirror of
https://github.com/flarum/framework.git
synced 2024-12-12 06:03:39 +08:00
Notification API tweaks
This commit is contained in:
parent
8cc47c77de
commit
efbe46f7a9
|
@ -19,7 +19,7 @@ class NotificationMailer
|
||||||
compact('notification', 'user'),
|
compact('notification', 'user'),
|
||||||
function ($message) use ($notification, $user) {
|
function ($message) use ($notification, $user) {
|
||||||
$message->to($user->email, $user->username)
|
$message->to($user->email, $user->username)
|
||||||
->subject('['.$this->forum->title.'] '.$notification->getEmailSubject());
|
->subject($notification->getEmailSubject());
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,12 +33,7 @@ class NotificationSyncer
|
||||||
*/
|
*/
|
||||||
public function sync(NotificationInterface $notification, array $users)
|
public function sync(NotificationInterface $notification, array $users)
|
||||||
{
|
{
|
||||||
$attributes = [
|
$attributes = $this->getAttributes($notification);
|
||||||
'type' => $notification::getType(),
|
|
||||||
'sender_id' => $notification->getSender()->id,
|
|
||||||
'subject_id' => $notification->getSubject()->id,
|
|
||||||
'data' => ($data = $notification->getData()) ? json_encode($data) : null
|
|
||||||
];
|
|
||||||
|
|
||||||
$toDelete = Notification::where($attributes)->get();
|
$toDelete = Notification::where($attributes)->get();
|
||||||
$toUndelete = [];
|
$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)
|
public function onePerUser(Closure $callback)
|
||||||
{
|
{
|
||||||
$this->sentTo = [];
|
$this->sentTo = [];
|
||||||
|
@ -92,4 +97,14 @@ class NotificationSyncer
|
||||||
|
|
||||||
$this->onePerUser = false;
|
$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
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user