From 24d7429e4f403003c30ac7e82a8ecc2d02c7c4c1 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Thu, 15 May 2025 22:21:46 +0200 Subject: [PATCH] fix(ActivityMonitor): prevent multiple event dispatches during polling --- app/Livewire/ActivityMonitor.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/Livewire/ActivityMonitor.php b/app/Livewire/ActivityMonitor.php index 024f53c3d..3bb76cc1f 100644 --- a/app/Livewire/ActivityMonitor.php +++ b/app/Livewire/ActivityMonitor.php @@ -22,6 +22,8 @@ class ActivityMonitor extends Component protected $activity; + public static $eventDispatched = false; + protected $listeners = ['activityMonitor' => 'newMonitorActivity']; public function newMonitorActivity($activityId, $eventToDispatch = 'activityFinished') @@ -51,15 +53,19 @@ public function polling() $causer_id = data_get($this->activity, 'causer_id'); $user = User::find($causer_id); if ($user) { - foreach ($user->teams as $team) { - $teamId = $team->id; + $teamId = $user->currentTeam()->id; + if (! self::$eventDispatched) { $this->eventToDispatch::dispatch($teamId); + self::$eventDispatched = true; } } return; } - $this->dispatch($this->eventToDispatch); + if (! self::$eventDispatched) { + $this->dispatch($this->eventToDispatch); + self::$eventDispatched = true; + } } } }