forked from eatvio/eatvio-infra
43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Events;
|
|
|
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
|
use Illuminate\Broadcasting\PrivateChannel;
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class ChatMessageUpdated implements ShouldBroadcast
|
|
{
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
|
|
|
public array $message;
|
|
|
|
/**
|
|
* Create a new event instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct(array $message)
|
|
{
|
|
$this->message = $message;
|
|
$this->dontBroadcastToCurrentUser();
|
|
}
|
|
|
|
/**
|
|
* Get the channels the event should broadcast on.
|
|
*
|
|
* @return \Illuminate\Broadcasting\Channel|array
|
|
*/
|
|
public function broadcastOn()
|
|
{
|
|
// return new Channel('direct-chat');
|
|
$chanId = (int) $this->message['to_user_id'] < (int) $this->message['from_user_id']
|
|
? $this->message['to_user_id'].'_'.$this->message['from_user_id']
|
|
: $this->message['from_user_id'].'_'.$this->message['to_user_id'];
|
|
|
|
return new PrivateChannel('direct-chat.'.$chanId);
|
|
}
|
|
}
|