From 9a98bdfbe61254bd7a903b045d715f288c0e7863 Mon Sep 17 00:00:00 2001 From: lkddi Date: Sat, 28 Feb 2026 11:17:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E8=81=8A=E5=A4=A9?= =?UTF-8?q?=E5=AE=A4=E5=88=9D=E6=AC=A1=E5=8A=A0=E8=BD=BD=E6=97=B6=E9=99=84?= =?UTF-8?q?=E5=B8=A6=E5=8E=86=E5=8F=B2=E6=B6=88=E6=81=AF=EF=BC=8C=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E5=9B=A0=E7=BD=91=E7=BB=9C=E5=BB=B6=E8=BF=9F=E9=94=99?= =?UTF-8?q?=E5=A4=B1=E5=85=A5=E5=9C=BA=E6=AC=A2=E8=BF=8E=E8=AF=AD=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/ChatController.php | 12 +++++++----- resources/views/chat/frame.blade.php | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/ChatController.php b/app/Http/Controllers/ChatController.php index 8067f58..533ea12 100644 --- a/app/Http/Controllers/ChatController.php +++ b/app/Http/Controllers/ChatController.php @@ -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, // 把历史消息附带给前端 ]); } diff --git a/resources/views/chat/frame.blade.php b/resources/views/chat/frame.blade.php index 414700e..1a35a1d 100644 --- a/resources/views/chat/frame.blade.php +++ b/resources/views/chat/frame.blade.php @@ -103,6 +103,22 @@ @include('chat.partials.scripts') + {{-- 页面初始加载时,渲染自带的历史记录(解决入场欢迎语错过断网的问题) --}} + @if (!empty($historyMessages)) + + @endif {{-- 进房特效自动播放:新人烟花礼包 / 周卡特效 --}} @if (!empty($newbieEffect) || !empty($weekEffect))