mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 13:10:37 -04:00
Move the shared team id and team channel logic of 15 broadcast events into a BroadcastsToTeam trait. Events no longer fall back to the session team: the session team can differ from the resource team, and queued jobs have no session. Fix StopDatabaseProxy, which dispatched DatabaseProxyStopped without a team, so the event was never broadcast from queued jobs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
35 lines
773 B
PHP
35 lines
773 B
PHP
<?php
|
|
|
|
namespace App\Traits;
|
|
|
|
use Illuminate\Broadcasting\PrivateChannel;
|
|
|
|
/**
|
|
* Broadcasts an event on the private channel of an explicit team.
|
|
*
|
|
* The team must come from the resource the event is about, never from the session:
|
|
* the session team can differ from the resource team (e.g. after a team switch in
|
|
* another tab), and queued jobs have no session at all.
|
|
*/
|
|
trait BroadcastsToTeam
|
|
{
|
|
public ?int $teamId = null;
|
|
|
|
public function __construct(?int $teamId)
|
|
{
|
|
$this->teamId = $teamId;
|
|
}
|
|
|
|
/**
|
|
* @return array<int, PrivateChannel>
|
|
*/
|
|
public function broadcastOn(): array
|
|
{
|
|
if (is_null($this->teamId)) {
|
|
return [];
|
|
}
|
|
|
|
return [new PrivateChannel("team.{$this->teamId}")];
|
|
}
|
|
}
|