From 368486e0c0db47dd5a6b39e3948250b41c74d1ee Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Tue, 12 Oct 2021 15:48:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=9C=A8=E6=9F=90?= =?UTF-8?q?=E4=BA=9B=E6=83=85=E5=86=B5=E4=B8=8B=E6=97=A0=E6=B3=95=E5=A4=84?= =?UTF-8?q?=E7=90=86=E6=8E=89=E6=9C=AA=E8=AF=BB=E5=B0=8F=E7=BA=A2=E7=82=B9?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared/redux/slices/chat.ts | 2 +- web/src/components/ChatBox/useMessageAck.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/shared/redux/slices/chat.ts b/shared/redux/slices/chat.ts index 488eb3ab..613fe4f4 100644 --- a/shared/redux/slices/chat.ts +++ b/shared/redux/slices/chat.ts @@ -15,7 +15,7 @@ interface ChatState { currentConverseId: string | null; // 当前活跃的会话id converses: Record; // <会话Id, 会话信息> ack: Record; // <会话Id, 本地最后一条会话Id> - lastMessageMap: Record; // <会话Id, 远程最后一条会话Id> + lastMessageMap: Record; // <会话Id, 远程会话列表最后一条会话Id> } const initialState: ChatState = { diff --git a/web/src/components/ChatBox/useMessageAck.ts b/web/src/components/ChatBox/useMessageAck.ts index 7789ebde..c47575a4 100644 --- a/web/src/components/ChatBox/useMessageAck.ts +++ b/web/src/components/ChatBox/useMessageAck.ts @@ -4,6 +4,7 @@ import { isValidStr, updateAck, useAppDispatch, + useAppSelector, useUpdateRef, } from 'tailchat-shared'; import { chatActions } from 'tailchat-shared/redux/slices'; @@ -12,7 +13,11 @@ import _debounce from 'lodash/debounce'; export function useMessageAck(converseId: string, messages: ChatMessage[]) { const messagesRef = useUpdateRef(messages); const dispatch = useAppDispatch(); + const lastMessageIdRef = useRef(''); + lastMessageIdRef.current = useAppSelector( + (state) => state.chat.ack[converseId] ?? '' + ); const setConverseAck = useMemo( () =>