mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 04:20:49 +08:00
topic_reply & hr_reached notification configurable
This commit is contained in:
@@ -102,6 +102,7 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||
'invites' => '邀请',
|
||||
];
|
||||
|
||||
public static array $notificationOptions = ['topic_reply', 'hr_reached'];
|
||||
|
||||
public function getClassTextAttribute(): string
|
||||
{
|
||||
@@ -555,6 +556,14 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||
return false;
|
||||
}
|
||||
|
||||
public function acceptNotification($name): bool
|
||||
{
|
||||
if (!isset($this->original['notifs'])) {
|
||||
throw new \RuntimeException("Not fetch field: notifs");
|
||||
}
|
||||
return str_contains($this->notifs, "[{$name}]");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ class HitAndRunRepository extends BaseRepository
|
||||
->with([
|
||||
'torrent' => function ($query) {$query->select(['id', 'size', 'name', 'category']);},
|
||||
'snatch',
|
||||
'user' => function ($query) {$query->select(['id', 'username', 'lang', 'class', 'donoruntil', 'enabled']);},
|
||||
'user' => function ($query) {$query->select(['id', 'username', 'lang', 'class', 'donoruntil', 'enabled', 'notifs']);},
|
||||
'user.language',
|
||||
]);
|
||||
if (!is_null($uid)) {
|
||||
@@ -297,8 +297,12 @@ class HitAndRunRepository extends BaseRepository
|
||||
do_log($hitAndRun->toJson() . ", [$logPrefix], affectedRows != 1, skip!", 'notice');
|
||||
return false;
|
||||
}
|
||||
$message = $this->geReachedMessage($hitAndRun);
|
||||
Message::query()->insert($message);
|
||||
if ($hitAndRun->user->acceptNotification('hr_reached')) {
|
||||
$message = $this->geReachedMessage($hitAndRun);
|
||||
Message::query()->insert($message);
|
||||
} else {
|
||||
do_log($hitAndRun->toJson() . ", [$logPrefix], user do not accept hr_reached notification", 'notice');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user