fix: ticket notification logic

Ticket assignees weren't always notified of new comments on tickets
This commit is contained in:
Roardom
2023-05-11 04:38:30 +00:00
parent 743dfe8f72
commit 7eb38d92e6
2 changed files with 51 additions and 5 deletions
+28 -3
View File
@@ -149,12 +149,37 @@ class Comment extends Component
$this->user->addProgress(new UserMade900Comments(), 1);
}
// Set Polymorhic Model Name
// Set Polymorphic Model Name
$modelName = str()->snake(class_basename($this->comment->commentable_type), ' ');
// New Comment Notification
if ($this->user->id !== $this->comment->user_id && $modelName !== 'collection') {
User::find($this->comment->user_id)->notify(new NewComment($modelName, $reply));
switch ($modelName) {
case 'ticket':
$ticket = $this->comment->commentable;
if ($this->user->id !== $ticket->staff_id && $ticket->staff_id !== null) {
User::find($ticket->staff_id)->notify(new NewComment($modelName, $reply));
}
if ($this->user->id !== $ticket->user_id) {
User::find($ticket->user_id)->notify(new NewComment($modelName, $reply));
}
if (! \in_array($this->comment->user_id, [$ticket->staff_id, $ticket->user_id, $this->user->id])) {
User::find($this->comment->user_id)->notify(new NewComment($modelName, $reply));
}
break;
case 'article':
case 'playlist':
case 'torrent request':
case 'torrent':
if ($this->user->id !== $this->comment->user_id) {
User::find($this->comment->user_id)->notify(new NewComment($modelName, $reply));
}
break;
}
// User Tagged Notification
+23 -2
View File
@@ -125,8 +125,29 @@ class Comments extends Component
$modelName = str()->snake(class_basename($this->model), ' ');
// New Comment Notification
if ($this->user->id !== $this->model->user_id && $modelName !== 'collection') {
User::find($this->model->user_id)->notify(new NewComment($modelName, $comment));
switch ($modelName) {
case 'ticket':
$ticket = $this->model;
if ($this->user->id !== $ticket->staff_id && $ticket->staff_id !== null) {
User::find($ticket->staff_id)->notify(new NewComment($modelName, $comment));
}
if ($this->user->id !== $ticket->user_id) {
User::find($ticket->user_id)->notify(new NewComment($modelName, $comment));
}
break;
case 'article':
case 'playlist':
case 'torrent request':
case 'torrent':
if ($this->user->id !== $this->model->user_id) {
User::find($this->model->user_id)->notify(new NewComment($modelName, $comment));
}
break;
}
// User Tagged Notification