43 lines
1.3 KiB
PHP
43 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\Communication\Events;
|
|
|
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
|
use Illuminate\Broadcasting\PrivateChannel;
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Modules\Communication\Entities\ChatMessage;
|
|
|
|
class MessageSent implements ShouldBroadcastNow
|
|
{
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
|
|
|
public function __construct(public ChatMessage $message, public int $businessId) {}
|
|
|
|
public function broadcastOn(): array
|
|
{
|
|
return [new PrivateChannel('business.'.$this->businessId.'.chat.'.$this->message->chat_room_id)];
|
|
}
|
|
|
|
public function broadcastAs(): string
|
|
{
|
|
return 'message.sent';
|
|
}
|
|
|
|
public function broadcastWith(): array
|
|
{
|
|
return [
|
|
'message' => [
|
|
'id' => $this->message->id,
|
|
'chat_room_id' => $this->message->chat_room_id,
|
|
'body' => $this->message->body,
|
|
'type' => $this->message->type,
|
|
'user_id' => $this->message->user_id,
|
|
'user' => $this->message->user,
|
|
'created_at' => $this->message->created_at?->toIso8601String(),
|
|
],
|
|
];
|
|
}
|
|
}
|