Skip to content

Commit

Permalink
Merge pull request #132 from Gamegoo-repo/fix/#130
Browse files Browse the repository at this point in the history
[Fix] 채팅 온오프 친구, 채팅 메시지 오류 수정
  • Loading branch information
yyypearl authored Oct 15, 2024
2 parents bd7f935 + 1d25a2e commit 3a1597c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/components/chat/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ const MessageList = (props: MessageListProps) => {
{showTime ? <YourDate>{setChatTimeFormatter(message.createdAt)}</YourDate> : null}
</YourDiv>
</YourMessageContainer>
) : (
) : message.senderId !== chatEnterData?.memberId && message.senderId !== 0 && (
<MyMessageContainer>
<MyDiv>
{showTime ? <MyDate>{setChatTimeFormatter(message.createdAt)}</MyDate> : null}
Expand Down
5 changes: 4 additions & 1 deletion src/hooks/useChatFriend.ts
Original file line number Diff line number Diff line change
@@ -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));
Expand Down
6 changes: 5 additions & 1 deletion src/hooks/useChatList.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
9 changes: 6 additions & 3 deletions src/hooks/useChatMessage.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -44,9 +47,9 @@ const useChatMessage = () => {
};

const handleMyMessage = (res: any) => {
if(res.data.
if (res.data.
chatroomUuid
===currentChatUuid){
=== currentChatUuid) {
const newMessage = res.data;
// 새로운 메시지 저장 (내가 쓴 메시지)
setNewMessage(newMessage);
Expand Down

0 comments on commit 3a1597c

Please sign in to comment.