Feat: 管理员进入聊天室自动触发烟花+公屏欢迎公告
This commit is contained in:
@@ -71,7 +71,28 @@ class ChatController extends Controller
|
||||
// 2. 广播 UserJoined 事件,通知房间内的其他人
|
||||
broadcast(new UserJoined($id, $user->username, $userData))->toOthers();
|
||||
|
||||
// 3. 获取历史消息用于初次渲染
|
||||
// 3. 管理员(superlevel)进入时:触发全房间烟花特效 + 公屏欢迎公告
|
||||
if ($user->user_level >= $superLevel) {
|
||||
// 广播烟花特效给所有在线用户
|
||||
broadcast(new \App\Events\EffectBroadcast($id, 'fireworks', $user->username));
|
||||
|
||||
// 发送欢迎公告消息(使用系统公告样式)
|
||||
$welcomeMsg = [
|
||||
'id' => $this->chatState->nextMessageId($id),
|
||||
'room_id' => $id,
|
||||
'from_user' => '系统公告',
|
||||
'to_user' => '大家',
|
||||
'content' => "🎉 欢迎管理员 <b>{$user->username}</b> 驾临本聊天室!请各位文明聊天!",
|
||||
'is_secret' => false,
|
||||
'font_color' => '#b91c1c',
|
||||
'action' => '',
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
];
|
||||
$this->chatState->pushMessage($id, $welcomeMsg);
|
||||
broadcast(new MessageSent($id, $welcomeMsg));
|
||||
}
|
||||
|
||||
// 4. 获取历史消息用于初次渲染
|
||||
// TODO: 可在前端通过请求另外的接口拉取历史记录,或者直接在这里 attach
|
||||
|
||||
// 渲染主聊天框架视图
|
||||
|
||||
Reference in New Issue
Block a user