helper = $helper; } /** * Handle the event. * * @param TaskUpdate $event * @return void */ public function handle(TaskUpdate $event) { $payload = $event->message; if (isset($payload->data->diff->assignee_id)) { $this->assigneeNotifHandler($payload); } if (isset($payload->data->diff->approver_id)) { $this->approverNotifHandler($payload); } if (isset($payload->data->diff->completed_at)) { $this->completedNotifHandler($payload); } if (isset($payload->data->diff->ready_to_test)) { $this->readyNotifHandler($payload); } } public function assigneeNotifHandler($payload) { $user = User::findOrFail($payload->data->diff->assignee_id); $task = Task::findOrFail($payload->data->original->id); $this->helper->makeNotif($payload, 'assignee', ['task' => $task->title]) ->sendNotifications($user, 'critical'); } public function approverNotifHandler($payload) { $user = User::findOrFail($payload->data->diff->approver_id); $task = Task::findOrFail($payload->data->original->id); $this->helper->makeNotif($payload, 'approver', ['task' => $task->title]) ->sendNotifications($user, 'critical'); } public function completedNotifHandler($payload){ $task = Task::findOrFail($payload->data->original->id); $user_ids = array_filter([ $task->approver_id, $task->assignee_id, $task->creator_id ]); $user_ids = array_unique(array_merge($user_ids, $task->watchers)); $users = User::whereIn('id', $user_ids)->where('id', '!=', auth()->id())->get(); $this->helper->makeNotif($payload, 'completed', ['task' => $task->title]) ->sendNotifications($users, 'critical'); } public function readyNotifHandler($payload) { $task = Task::findOrFail($payload->data->original->id); $user_ids = array_unique(array_filter([ $task->approver_id, $task->assignee_id, $task->creator_id ])); $users = User::whereIn('id', $user_ids)->where('id', '!=', auth()->id())->get(); $this->helper->makeNotif($payload, 'ready', ['task' => $task->title]) ->sendNotifications($users, 'critical'); } }