diff --git a/src/Events/Message/Events.php b/src/Events/Message/Events.php index dc6ca7c..3f0a8be 100644 --- a/src/Events/Message/Events.php +++ b/src/Events/Message/Events.php @@ -55,18 +55,11 @@ public function broadcastWhen() public function broadcastOn() { $event = $this->event; - $conversation_id = $this->conversation_id; - if ( - $event->type == 'delete' - && $event->made_type == Config::config('models.message') - ) { - if ($event->all) { - return new PrivateChannel("message-event-created.{$conversation_id}"); - } else { - return new PrivateChannel("message-event.user.{$this->event->maker_id}"); - } + if ($event->type == 'delete' && !$event->all && $event->made_type == 'App\\Models\\Message') { + return new PrivateChannel("message-event.user.{$this->event->maker_id}"); } else { - return new PrivateChannel("message-event-created.{$this->event->made_id}"); + $participant_ids = $event->made->participants()->pluck('user_id')->toArray(); + return array_map(fn ($id) => new PrivateChannel("message-event.user.{$id}"), $participant_ids); } } } diff --git a/src/routes/channels.php b/src/routes/channels.php index 83639a0..ad3ff1e 100644 --- a/src/routes/channels.php +++ b/src/routes/channels.php @@ -15,7 +15,6 @@ | used to check if an authenticated user can listen to the channel. | */ -Broadcast::channel('message-event-created.{conversation}', ConversationChannel::class); Broadcast::channel('message-created.{conversation}', ConversationChannel::class); Broadcast::channel('message-new.user.{user}', UserMessageChannel::class); Broadcast::channel('message-event.user.{user}', UserMessageChannel::class);