From 6ea967b99899d88b6c487b3cadcb43e94e06ba55 Mon Sep 17 00:00:00 2001 From: Clara Date: Tue, 15 Oct 2024 21:41:35 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix(#130):=20=EB=82=A8=EC=9D=B4=20=EC=93=B4?= =?UTF-8?q?=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=B1=84=ED=8C=85=EC=B0=BD?= =?UTF-8?q?=EC=97=90=20=EB=B3=B4=EC=9D=B4=EB=8A=94=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/chat/MessageList.tsx | 2 +- src/hooks/useChatMessage.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/chat/MessageList.tsx b/src/components/chat/MessageList.tsx index 9c31d606..b903c17a 100644 --- a/src/components/chat/MessageList.tsx +++ b/src/components/chat/MessageList.tsx @@ -386,7 +386,7 @@ const MessageList = (props: MessageListProps) => { {showTime ? {setChatTimeFormatter(message.createdAt)} : null} - ) : ( + ) : message.senderId !== chatEnterData?.memberId && message.senderId !== 0 && ( {showTime ? {setChatTimeFormatter(message.createdAt)} : null} diff --git a/src/hooks/useChatMessage.ts b/src/hooks/useChatMessage.ts index 5c5c8ed7..5ba4691a 100644 --- a/src/hooks/useChatMessage.ts +++ b/src/hooks/useChatMessage.ts @@ -44,9 +44,9 @@ const useChatMessage = () => { }; const handleMyMessage = (res: any) => { - if(res.data. + if (res.data. chatroomUuid - ===currentChatUuid){ + === currentChatUuid) { const newMessage = res.data; // 새로운 메시지 저장 (내가 쓴 메시지) setNewMessage(newMessage); From 1d25a2e558da6e7057b49efb1700f13556b8a1b1 Mon Sep 17 00:00:00 2001 From: Clara Date: Tue, 15 Oct 2024 21:43:01 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix(#130):=20=EC=98=A8/=EC=98=A4=ED=94=84?= =?UTF-8?q?=EB=9D=BC=EC=9D=B8=20=EC=B9=9C=EA=B5=AC=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useChatFriend.ts | 5 ++++- src/hooks/useChatList.ts | 6 +++++- src/hooks/useChatMessage.ts | 5 ++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/hooks/useChatFriend.ts b/src/hooks/useChatFriend.ts index 3293a25c..15115a5a 100644 --- a/src/hooks/useChatFriend.ts +++ b/src/hooks/useChatFriend.ts @@ -1,12 +1,15 @@ import { useEffect, useState } from 'react'; import { useDispatch } from 'react-redux'; -import { socket } from '@/socket'; +import { connectSocket, socket } from '@/socket'; import { setFriendOffline, setFriendOnline, setMemberId } from '@/redux/slices/chatSlice'; const useChatFriend = () => { const dispatch = useDispatch(); useEffect(() => { + // 소켓 연결되어 있지 않으면 소켓 연결 + connectSocket(); + const handleMemberInfo = (res: any) => { const memberId = res.data.memberId; dispatch(setMemberId(memberId)); diff --git a/src/hooks/useChatList.ts b/src/hooks/useChatList.ts index 2f688632..fed84e07 100644 --- a/src/hooks/useChatList.ts +++ b/src/hooks/useChatList.ts @@ -1,10 +1,14 @@ import { useEffect } from 'react'; -import { socket } from '@/socket'; +import { connectSocket, socket } from '@/socket'; import { getChatrooms } from '@/api/chat'; import { ChatroomList } from '@/interface/chat'; const useChatList = (setChatrooms: (chatrooms: ChatroomList[]) => void) => { + useEffect(() => { + // 소켓 연결되어 있지 않으면 소켓 연결 + connectSocket(); + const handleJoinedNewChatroom = async () => { try { const data = await getChatrooms(); diff --git a/src/hooks/useChatMessage.ts b/src/hooks/useChatMessage.ts index 5ba4691a..ead522f8 100644 --- a/src/hooks/useChatMessage.ts +++ b/src/hooks/useChatMessage.ts @@ -1,7 +1,7 @@ import { useEffect, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { RootState } from '@/redux/store'; -import { socket } from '@/socket'; +import { connectSocket, socket } from '@/socket'; import { setUnreadUuid } from '@/redux/slices/chatSlice'; import { markChatAsRead } from '@/api/chat'; import { SystemMessage, ChatMessageDto } from '@/interface/chat'; @@ -16,6 +16,9 @@ const useChatMessage = () => { const unreadChatUuids = useSelector((state: RootState) => state.chat.unreadUuids); useEffect(() => { + // 소켓 연결되어 있지 않으면 소켓 연결 + connectSocket(); + const handleChatMessage = (res: any) => { const chatroomUuid = res.data.chatroomUuid; const newChatTimestamp = res.data.timestamp;