1
0
mirror of https://github.com/flarum/core.git synced 2025-08-13 03:44:32 +02:00

went over most of the changed attributes from the other pr

This commit is contained in:
Daniel Klabbers
2018-04-17 14:22:38 +02:00
parent efa3b62fb8
commit a2927b725f
21 changed files with 122 additions and 106 deletions

View File

@@ -34,9 +34,9 @@ use Flarum\User\User;
* @property string $type
* @property int|null $subject_id
* @property mixed|null $data
* @property \Carbon\Carbon $time
* @property bool $is_read
* @property bool $is_deleted
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $read_at
* @property \Carbon\Carbon $deleted_at
* @property \Flarum\User\User|null $user
* @property \Flarum\User\User|null $sender
* @property \Flarum\Database\AbstractModel|null $subject
@@ -51,7 +51,7 @@ class Notification extends AbstractModel
/**
* {@inheritdoc}
*/
protected $dates = ['time'];
protected $dates = ['created_at', 'read_at', 'deleted_at'];
/**
* A map of notification types and the model classes to use for their
@@ -70,7 +70,7 @@ class Notification extends AbstractModel
*/
public function read()
{
$this->is_read = true;
$this->read_at = time();
}
/**

View File

@@ -27,11 +27,11 @@ class NotificationRepository
{
$primaries = Notification::select(
app('flarum.db')->raw('MAX(id) AS id'),
app('flarum.db')->raw('SUM(is_read = 0) AS unread_count')
app('flarum.db')->raw('SUM(read_at IS NULL) AS unread_count')
)
->where('user_id', $user->id)
->whereIn('type', $user->getAlertableNotificationTypes())
->where('is_deleted', false)
->whereNull('deleted_at')
->groupBy('type', 'subject_id')
->orderByRaw('MAX(time) DESC')
->skip($offset)
@@ -40,7 +40,7 @@ class NotificationRepository
return Notification::select('notifications.*', app('flarum.db')->raw('p.unread_count'))
->mergeBindings($primaries->getQuery())
->join(app('flarum.db')->raw('('.$primaries->toSql().') p'), 'notifications.id', '=', app('flarum.db')->raw('p.id'))
->latest('time')
->latest('created_at')
->get();
}
@@ -53,6 +53,6 @@ class NotificationRepository
*/
public function markAllAsRead(User $user)
{
Notification::where('user_id', $user->id)->update(['is_read' => true]);
Notification::where('user_id', $user->id)->update(['read_at' => time()]);
}
}