From f13cdf4d46bba928d593b115ad7d2c64a54c8e58 Mon Sep 17 00:00:00 2001 From: mahdihty Date: Mon, 15 Mar 2021 14:54:31 +0330 Subject: [PATCH] some bug fix and change in notification and listener --- app/Http/Controllers/NotificationController.php | 3 ++- app/Listeners/BusinessUserCreateNotif.php | 5 +++-- app/Listeners/ProjectUserCreateNotif.php | 2 +- app/Notifications/FcmNotification.php | 1 + app/Utilities/HelperClass/NotificationHelper.php | 3 ++- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/NotificationController.php b/app/Http/Controllers/NotificationController.php index 28d8393..f21e5bc 100644 --- a/app/Http/Controllers/NotificationController.php +++ b/app/Http/Controllers/NotificationController.php @@ -9,7 +9,8 @@ class NotificationController extends Controller { public function index($business) { - return Auth::user()->notifications()->where('business_id', $business)->get(); + return Auth::user()->notifications() + ->where('data->business_id', $business)->get(); } public function markAsRead($business, $notification) diff --git a/app/Listeners/BusinessUserCreateNotif.php b/app/Listeners/BusinessUserCreateNotif.php index 764cd5f..1eb52bc 100644 --- a/app/Listeners/BusinessUserCreateNotif.php +++ b/app/Listeners/BusinessUserCreateNotif.php @@ -36,11 +36,12 @@ class BusinessUserCreateNotif $payload = $event->message; if ($payload->data->original->level === enum('levels.inactive.id')) { // When user level in business is zero, probably user added to business by system - // And not necessary send notification to stockholders + // And not necessary send notification to stakeholders return; } $new_user = User::findOrFail($payload->data->original->user_id); - $owners = Business::findOrFail($payload->business)->owners()->where('id', '!=', $new_user->id)->get(); + $owners = Business::findOrFail($payload->business)->owners() + ->whereNotIn('id', [$new_user->id, auth()->id()])->get(); $users = $owners->prepend($new_user); diff --git a/app/Listeners/ProjectUserCreateNotif.php b/app/Listeners/ProjectUserCreateNotif.php index eb0a09f..09b6e3f 100644 --- a/app/Listeners/ProjectUserCreateNotif.php +++ b/app/Listeners/ProjectUserCreateNotif.php @@ -37,7 +37,7 @@ class ProjectUserCreateNotif $new_user = User::findOrFail($payload->data->original->user_id); $project = Project::findOrFail($payload->data->original->project_id); $owners_id = request('_business_info')['info']['projects'][$project->id]['members']->reject(function ($item, $key) use ($new_user) { - return $item['level'] < enum('levels.owner.id') || $key === $new_user->id; + return $item['level'] < enum('levels.owner.id') || $key === $new_user->id || $key === auth()->id(); })->toArray(); $owners = User::whereIn('id', array_keys($owners_id))->get(); diff --git a/app/Notifications/FcmNotification.php b/app/Notifications/FcmNotification.php index 0c51e59..c1b9c36 100644 --- a/app/Notifications/FcmNotification.php +++ b/app/Notifications/FcmNotification.php @@ -45,6 +45,7 @@ class FcmNotification extends Notification ->data([ 'title' => $this->message['title'], 'body' => $this->message['body'], + 'openURL' => "https://facebook.com/" ]); } diff --git a/app/Utilities/HelperClass/NotificationHelper.php b/app/Utilities/HelperClass/NotificationHelper.php index 41239c2..d128e9c 100644 --- a/app/Utilities/HelperClass/NotificationHelper.php +++ b/app/Utilities/HelperClass/NotificationHelper.php @@ -27,7 +27,8 @@ class NotificationHelper 'greeting' => $this->getMessageLine($payload, $route.'greeting'), 'subject' => $this->getMessageLine($payload, $route.'subject'), 'title' => $this->getMessageLine($payload, $route.'title'), - 'body' => $this->getMessageLine($payload, $route.'body', $options) + 'body' => $this->getMessageLine($payload, $route.'body', $options), + 'business_id' => request('_business_info')['id'] ]; return $this; }