Files
UNIT3D-Community-Edition/app/Events/MessageSent.php
2018-05-16 16:17:30 -04:00

69 lines
1.6 KiB
PHP

<?php
/**
* NOTICE OF LICENSE
*
* UNIT3D is open-sourced software licensed under the GNU General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
* @author HDVinnie
*/
namespace App\Events;
use App\Http\Resources\ChatMessageResource;
use App\Message;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class MessageSent implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Message details
*
* @var Message
*/
public $message;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Message $message)
{
$message = Message::with([
'user.group',
'user.chatStatus',
'receiver.group',
'receiver.chatStatus'
])->find($message->id);
$this->message = new ChatMessageResource($message);
}
/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
*/
public function broadcastOn()
{
// $this->dontBroadcastToCurrentUser();
return new PresenceChannel('chatroom.' . $this->message->chatroom_id);
}
public function broadcastAs()
{
return 'new.message';
}
}