[FEAT] 채팅 REST 및 소켓 연동 훅 추가 - #65
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthrough채팅 도메인 타입과 커서 페이지네이션을 추가했습니다. 채팅방·메시지 HTTP API와 인증 범위 Query Key를 연결했습니다. 조회 훅과 채팅방 소켓 참가·수신·전송 흐름을 추가했습니다. Changes채팅 기능
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant useChatRoomSocket
participant SocketConnection
participant ChatRoomServer
useChatRoomSocket->>SocketConnection: 채팅방 참가 요청
SocketConnection->>ChatRoomServer: roomId와 마지막 메시지 ID 전송
ChatRoomServer-->>SocketConnection: 참가 ACK 또는 오류
SocketConnection-->>useChatRoomSocket: 참가 결과 전달
ChatRoomServer-->>SocketConnection: 신규 메시지 이벤트 전송
SocketConnection-->>useChatRoomSocket: 같은 roomId의 메시지 전달
useChatRoomSocket->>SocketConnection: 메시지 전송
SocketConnection->>ChatRoomServer: 메시지 전송 이벤트
ChatRoomServer-->>SocketConnection: 메시지 ACK
SocketConnection-->>useChatRoomSocket: Promise 결과 반환
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/hooks/useChatRoomSocket.ts`:
- Around line 42-50: Update handleJoined in useChatRoomSocket to invoke onJoined
only when response.room.roomId matches the current roomId, mirroring the room
filter used by handleMessage. Preserve the existing joined-response handling for
the active room.
- Line 59: In src/hooks/useChatRoomSocket.ts at lines 59-59 and 76-76, store
onJoined, onMessage, and onJoinError in refs and invoke the current ref values
inside the effect handlers and join acknowledgement. Remove these consumer
callbacks from the respective dependency arrays, leaving [canConnect, roomId,
socket] at lines 59-59 and [canConnect, isConnected, roomId, socket] at lines
76-76 so listeners and room joins are not recreated on callback identity
changes.
- Around line 78-96: Update sendMessage to emit through
socket.timeout(SOCKET_ACK_TIMEOUT_MS), extracting SOCKET_ACK_TIMEOUT_MS as a
constant, and handle the timeout callback by resolving a failed ack with code
SOCKET_TIMEOUT and the payload’s clientMessageId; preserve the existing
disconnected response and successful ack behavior.
In `@src/lib/api/chat.ts`:
- Around line 22-24: Update the cursor condition in the ChatMessageListParams
query-building logic to omit only null or undefined values, while preserving
cursor=0 by setting it through searchParams.set. Keep the existing
String(cursor) conversion and request behavior for all valid numeric cursors.
In `@src/lib/constants/queryKeys.ts`:
- Around line 117-120: Update the chat query key builders ROOM, MESSAGES_ROOT,
and MESSAGES to include the authenticated user’s authScope in every key,
ensuring useChatRoom and useChatMessages do not share cached data across users.
Propagate authScope through their callers while preserving roomId and limit
distinctions.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: dec86af8-1f9a-483c-a17e-6dfccd369e11
📒 Files selected for processing (9)
src/hooks/useChatMessages.tssrc/hooks/useChatRoom.tssrc/hooks/useChatRoomSocket.tssrc/lib/api/chat.tssrc/lib/api/fetchInstance.tssrc/lib/constants/apiRoutes.tssrc/lib/constants/queryKeys.tssrc/types/chat.tssrc/types/pagination.ts
|
성현님, 수정이 필요한 아래 부분 모두 코드래빗 코멘트에 있어서 따로 인라인 코멘트는 달지 않도록 하겠습니다.
|
📋 작업 내용
🔥 변경 사항
chat:room:join,chat:message:send,chat:message:new연동 훅 추가missedMessages.messages,hasMore,nextMessageId타입 반영chat:room:joinack callback 처리 추가fetchInstance.getPaginated가 cursor pagination 타입도 받을 수 있도록 generic pagination 타입 지원✅ 체크리스트
📷 스크린샷 (선택)
🔗 관련 이슈
Closes #
💬 To Reviewer
nextCursor기반 infinite query로 조회합니다.lastMessageId를 전달해 재연결 이후 누락 메시지를 복구할 수 있도록 구성했습니다.missedMessages는 단순 배열이 아니라{ messages, hasMore, nextMessageId }구조로 정의했습니다.chat:room:joined이벤트 payload와chat:room:joinack payload 구조가 달라 타입을 분리했습니다.Summary by CodeRabbit