diff --git a/src/components/chat/MessageInput.tsx b/src/components/chat/MessageInput.tsx index f20d4d4..13061c0 100644 --- a/src/components/chat/MessageInput.tsx +++ b/src/components/chat/MessageInput.tsx @@ -9,7 +9,7 @@ import useSocketStore from '@/store/socket'; import Dialog from '../common/dialog/Dialog'; interface CharacterState { - characterId: string, + characterId: number, characterName: string } diff --git a/src/pages/chats/[character].tsx b/src/pages/chats/[character].tsx index 92c11a8..17e866a 100644 --- a/src/pages/chats/[character].tsx +++ b/src/pages/chats/[character].tsx @@ -42,7 +42,7 @@ const Character = ({ />
- + { settingModal && ( { setSettingModal(false); }} theme="white"> diff --git a/src/store/socket.ts b/src/store/socket.ts index 5821f09..2a5357f 100644 --- a/src/store/socket.ts +++ b/src/store/socket.ts @@ -8,7 +8,7 @@ interface SocketState { chatStore?: ChatState; processingmessageTime: Array; connect: (accessToken: string) => void; - sendMessage: (characterId: string, characterName:string, message:string) => void; + sendMessage: (characterId: number, characterName:string, message:string) => void; setChatStore: (chatSate:ChatState) => void; } @@ -19,14 +19,14 @@ export interface Chat { export interface MessageFromClient { content: string; - characterId: string; + characterId: number; createdAt: number; characterName: string; } export interface MessageToClient extends Chat { messageId: string; - characterId: string; + characterId: number; createdAt: number; characterName: string; /** @@ -71,7 +71,7 @@ const useSocketStore = create((set, get) => ({ get().socket!.on('connect', async () => { get().socket!.on('subscribe', (msg) => { const characterId = getCurrentCharacterId(); - if (!characterId || msg.characterId === characterId) return; + if (characterId === null || msg.characterId !== characterId) return; if (msg.fromUser) { get().chatStore?.addChatContents({ speaker: 'me', content: msg.content, timestamp: msg.createdAt, loading: false, @@ -123,7 +123,11 @@ const useSocketStore = create((set, get) => ({ function getCurrentCharacterId() { const pathMatcher = window.location.pathname.match(/\/chats\/([\d]+)$/); if (pathMatcher && pathMatcher.length === 2) { - return pathMatcher[1]; + try { + return Number(pathMatcher[1]); + } catch (error) { + return null; + } } return null; }