Skip to content

Commit

Permalink
improved message event
Browse files Browse the repository at this point in the history
  • Loading branch information
myckhel committed Jun 18, 2021
1 parent e868db5 commit 2341ace
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
15 changes: 4 additions & 11 deletions src/Events/Message/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
1 change: 0 additions & 1 deletion src/routes/channels.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 2341ace

Please sign in to comment.