Skip to content

Commit dd4dc42

Browse files
authored
[Fix] 게임에 새롭게 입장하거나 재입장 한 경우 이전 채팅 기록이 보이지 않는 문제를 해결 한다. (#337)
fix : 새롭게 배틀 입장 시 이전 채팅 기록이 보이지 않는 버그 수정 - 최초에 배틀 입장시 진행중인 게임과 동기화 하는 로직중에 채팅을 전체/팀 메세지 구분하는 scope 인자가 잘못된 조건으로 구분되어 battleStore에 제대로된 채팅 로그를 동기화 하지 않는 문제를 수정했습니다
1 parent 051628b commit dd4dc42

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

frontend/src/pages/battlePage/hooks/useBattleChat.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@ export function useBattleChat() {
2121
const addChat = useBattleStore((state) => state.addChat);
2222
const user = useAuthStore(selectUser);
2323

24-
// 팀 채팅
2524
const teamMessages = useMemo(() => {
2625
if (!user) return [];
27-
const myTeamChats = teamChats
28-
.filter((chat) => chat.team === team && chat.scope === 'TEAM' && (!chat.type || chat.type === 'chat'))
29-
.map((chat) => convertBattleChatToMessage(chat));
26+
27+
const myTeamChats = teamChats.map((chat) => convertBattleChatToMessage(chat));
3028

3129
return myTeamChats.sort((a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime());
32-
}, [teamChats, team, user]);
33-
// 전체 채팅
30+
}, [teamChats, user]);
3431

3532
const allMessages = useMemo(() => {
3633
if (!user) return [];
@@ -46,7 +43,6 @@ export function useBattleChat() {
4643
if (team === 'NONE' || !opponentNoticeChat) return null;
4744
return convertBattleChatToMessage(opponentNoticeChat);
4845
}, [opponentNoticeChat, team, user]);
49-
// 실시간 채팅 업데이트 이벤트 구독
5046

5147
useEffect(() => {
5248
if (!socket) return;
@@ -58,7 +54,7 @@ export function useBattleChat() {
5854
socket.off('battle:chatted', handleChatUpdate);
5955
};
6056
}, [socket, addChat]);
61-
// 메시지 전송
57+
6258
const sendMessage = useCallback(
6359
(content: string, scope: 'TEAM' | 'ALL') => {
6460
if (!socket || !user) return;

frontend/src/pages/battlePage/stores/battleStore.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,7 @@ export const useBattleStore = create<BattleStore>((set, get) => ({
161161
if (chat.scope === 'TEAM') {
162162
return { teamChats: [...state.teamChats, chat] };
163163
} else {
164-
return {
165-
allChats: [...state.allChats, chat],
166-
teamChats: [...state.teamChats, chat]
167-
};
164+
return { allChats: [...state.allChats, chat] };
168165
}
169166
}),
170167
setSelectedTeam: (team) => set({ selectedTeam: team }),

0 commit comments

Comments
 (0)