修复:聊天室初次加载时附带历史消息,解决因网络延迟错失入场欢迎语的问题

This commit is contained in:
2026-02-28 11:17:09 +08:00
parent cb2e962116
commit 9a98bdfbe6
2 changed files with 23 additions and 5 deletions

View File

@@ -122,14 +122,16 @@ class ChatController extends Controller
}
// 5. 获取历史消息用于初次渲染
// TODO: 可在前端通过请求另外的接口拉取历史记录,或者直接在这里 attach
// 获取最近的所有消息(由于 Redis list 已限制保留条数,传 0 为拉取所有缓存的记录)
$historyMessages = $this->chatState->getNewMessages($id, 0);
// 渲染主聊天框架视图
return view('chat.frame', [
'room' => $room,
'user' => $user,
'weekEffect' => $this->shopService->getActiveWeekEffect($user), // 周卡特效(登录自动播放)
'newbieEffect' => $newbieEffect, // 新人入场专属特效
'room' => $room,
'user' => $user,
'weekEffect' => $this->shopService->getActiveWeekEffect($user), // 周卡特效(登录自动播放)
'newbieEffect' => $newbieEffect, // 新人入场专属特效
'historyMessages' => $historyMessages, // 把历史消息附带给前端
]);
}