From 3e6e57dab04e562fabcde4e7cc333569f13c6107 Mon Sep 17 00:00:00 2001 From: ItzCrazyKns <95534749+ItzCrazyKns@users.noreply.github.com> Date: Thu, 17 Oct 2024 18:51:11 +0530 Subject: [PATCH] feat(chat-window): fix rewrite, use messageID --- ui/components/ChatWindow.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index a80a5c9..986f8ae 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -333,8 +333,9 @@ const ChatWindow = ({ id }: { id?: string }) => { } }, [isMessagesLoaded, isWSReady]); - const sendMessage = async (message: string) => { + const sendMessage = async (message: string, messageId?: string) => { if (loading) return; + setLoading(true); setMessageAppeared(false); @@ -342,12 +343,13 @@ const ChatWindow = ({ id }: { id?: string }) => { let recievedMessage = ''; let added = false; - const messageId = crypto.randomBytes(7).toString('hex'); + messageId = messageId ?? crypto.randomBytes(7).toString('hex'); ws?.send( JSON.stringify({ type: 'message', message: { + messageId: messageId, chatId: chatId!, content: message, }, @@ -474,7 +476,7 @@ const ChatWindow = ({ id }: { id?: string }) => { return [...prev.slice(0, messages.length > 2 ? index - 1 : 0)]; }); - sendMessage(message.content); + sendMessage(message.content, message.messageId); }; useEffect(() => {