|
@@ -4,7 +4,10 @@ namespace App\Listeners;
|
|
|
|
|
|
use App\Events\ObjectActionCreate;
|
|
|
use App\Models\Enums\ActionObjectType;
|
|
|
+use App\Models\Enums\NotificationObjectType;
|
|
|
use App\Models\Enums\ObjectAction;
|
|
|
+use App\Models\Notification;
|
|
|
+use App\Models\NotificationRecord;
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
|
@@ -23,7 +26,33 @@ class SendActionBrowserNotification implements ShouldQueue
|
|
|
*/
|
|
|
public function handle(ObjectActionCreate $event): void
|
|
|
{
|
|
|
+ $actionObjectType = ActionObjectType::tryFrom($event->action->object_type);
|
|
|
+
|
|
|
+ $object = $actionObjectType->modelBuilder()->find($event->action->object_id);
|
|
|
+ if (! $object) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $userIds = match ($actionObjectType) {
|
|
|
+ ActionObjectType::TASK => $object->assign > 0 ? [$object->assign] : [],
|
|
|
+ default => [],
|
|
|
+ };
|
|
|
|
|
|
+ if (! $userIds) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $notification = Notification::query()->create([
|
|
|
+ 'object_type' => NotificationObjectType::ACTION->value,
|
|
|
+ 'object_id' => $event->action->id,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ foreach ($userIds as $userId) {
|
|
|
+ NotificationRecord::query()->create([
|
|
|
+ 'notification_id' => $notification->id,
|
|
|
+ 'user_id' => $userId,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public function shouldQueue(ObjectActionCreate $event): bool
|