Files
chatroom/app/Events/UserMuted.php
lkddi 14c4effefa 新增:管理员命令系统(警告/踢出/禁言/冻结/查看私信/站长公屏)
- 新建 AdminCommandController 处理6个管理操作命令
- 注册管理员命令路由 /command/*
- 更新 UserKicked 事件增加原因字段
- 更新 UserMuted 事件支持自定义提示消息
- 重构用户名片弹窗管理面板:警告/踢出/禁言/冻结按钮
- 站长专属:查看私信记录、📢公屏讲话按钮
- 被踢出时显示踢出原因
2026-02-26 22:27:49 +08:00

67 lines
1.7 KiB
PHP

<?php
/**
* 文件功能:用户被封口/解封广播事件
*
* @author ChatRoom Laravel
*
* @version 1.0.0
*/
namespace App\Events;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class UserMuted implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*
* @param int $roomId 房间ID
* @param string $username 被封口的用户昵称
* @param int $muteTime 封口时长(如 10 分钟),如果为 0 则是解封
*/
public function __construct(
public readonly int $roomId,
public readonly string $username,
public readonly int $muteTime,
public readonly string $message = '',
) {}
/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PresenceChannel('room.'.$this->roomId),
];
}
/**
* 获取广播时的数据
*
* @return array<string, mixed>
*/
public function broadcastWith(): array
{
$statusMessage = $this->message ?: ($this->muteTime > 0
? "用户 [{$this->username}] 已被禁言 {$this->muteTime} 分钟。"
: "用户 [{$this->username}] 已被解除禁言。");
return [
'username' => $this->username,
'mute_time' => $this->muteTime,
'message' => $statusMessage,
];
}
}