1
0
mirror of https://github.com/flarum/core.git synced 2025-07-30 13:10:24 +02:00

More powerful/extensible notifications

- Notifications can be delivered in multiple ways (alert, email)
- Different notification types can implement interfaces to allow
themselves to be delivered in these various ways
- User preferences for each notification type/method combination are
automatically registered
This commit is contained in:
Toby Zerner
2015-03-28 15:43:31 +10:30
parent 49c3fa09e6
commit bc9be30a02
15 changed files with 292 additions and 43 deletions

View File

@@ -356,7 +356,7 @@ class User extends Model
$defaults[$k] = $v['default'];
}
return array_merge($defaults, (array) json_decode($value, true));
return array_merge($defaults, array_only((array) json_decode($value, true), array_keys(static::$preferences)));
}
public function setPreferencesAttribute($value)
@@ -372,6 +372,16 @@ class User extends Model
];
}
public static function notificationPreferenceKey($type, $sender)
{
return 'notify_'.$type.'_'.$sender;
}
public function shouldNotify($type, $method)
{
return $this->preference(static::notificationPreferenceKey($type, $method));
}
public function preference($key, $default = null)
{
return array_get($this->preferences, $key, $default);