Enhance ShikshalokamChat and ShikshalokamVoiceBasedChat components by… - #215
Conversation
… integrating chat history management. Update createMessage function to include 'received' status and improve chat history filtering logic. Refactor imports for better organization.
WalkthroughAdds a Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/pages/ShikshalokamVoiceChat/voice-chat.js(3 hunks)src/pages/interview-voice/index.js(1 hunks)src/pages/shikshalokamChat.js(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/pages/shikshalokamChat.js (2)
src/hooks/useStorage.js (4)
useUserStorage(24-26)useUserStorage(24-26)useChatStorage(20-22)useChatStorage(20-22)src/hooks/useSmartChatStorage.js (3)
useChatStorage(5-5)chatHistory(4-4)useSmartChatStorage(3-12)
src/pages/ShikshalokamVoiceChat/voice-chat.js (1)
src/pages/interview-voice/index.js (2)
createMessage(1-6)createMessage(1-6)
🔇 Additional comments (7)
src/pages/interview-voice/index.js (1)
1-6: LGTM! Clean addition of message delivery tracking.The
receivedparameter addition is well-implemented with an appropriate default value offalsefor newly created messages. This change enables delivery confirmation tracking across the chat system.src/pages/ShikshalokamVoiceChat/voice-chat.js (2)
745-745: LGTM! Correct handling of historical intro message.Setting
received: truefor the intro message loaded from storage is appropriate, as this represents a previously received message being restored to the chat history.
843-850: LGTM! Consistent handling of bot message received status.Bot messages are correctly marked with
received: truewhen added to chat history, maintaining consistency with the delivery tracking pattern throughout the application.src/pages/shikshalokamChat.js (4)
1-1: LGTM! All new imports are properly utilized.The added imports support the chat history management, loading indicators, and routing functionality introduced in this PR.
Also applies to: 10-13
26-26: LGTM! Proper state management for chat history and IP fetch status.The additions of
ipFetchedtracking andchatHistoryfromuseSmartChatStoragecorrectly support the enhanced initialization flow and loading states.Also applies to: 34-34, 43-43
164-165: LGTM! Robust loading state management with proper cleanup.The IP fetch status is correctly managed:
- Set to
falsebefore starting the async setup- Set to
truein thefinallyblock to ensure it's always updated- Loading indicator properly reflects both general loading and IP fetch status
Also applies to: 175-181
47-51: Cleanup logic on mount intentionally discards unacknowledged pending messages.The effect filters out unreceived messages on app startup. Based on the codebase, this is intentional design:
- Unreceived messages represent user messages waiting for server acknowledgment (see
voice-chat.jslines 278-281 where unreceived status is toggled when the server responds)- Messages created with
received: falseare temporary pending states, not persistent queued messages- If a message remained unreceived when the app closed, it means the server never acknowledged it, so discarding it requires the user to resend
- No retry mechanism depends on persisting unreceived messages (S3 upload retry logic is separate)
- Similar cleanup pattern appears in voice chat reconnection logic
This is a deliberate choice to start with a clean message history rather than trying to recover unacknowledged pending messages. Consider documenting this behavior if unclear to future maintainers.
| if (message.source === "user") { | ||
| const chat_history = getChatHistory() | ||
| const updated_chat_history = chat_history.slice(0).map(chat => { | ||
| if (!chat.received && chat.msg === message.msg) { | ||
| return createMessage({ ...chat, received: true }) | ||
| } | ||
| return chat | ||
| }) | ||
| setChatHistory(updated_chat_history) | ||
| } |
There was a problem hiding this comment.
Fix message matching logic to prevent marking multiple messages as received.
The current logic has several issues:
- Marks all matching messages: If a user sends identical text twice, all unreceived messages with that text will be marked as received, not just the one being acknowledged
- Text-based matching is fragile: Messages should be matched by unique identifiers (e.g., timestamp, server ID, or client-generated UUID) rather than content
- Unnecessary wrapper call: Line 281 uses
createMessage({ ...chat, received: true })when{ ...chat, received: true }would suffice
Apply this diff to fix the logic:
if (message.source === "user") {
const chat_history = getChatHistory()
- const updated_chat_history = chat_history.slice(0).map(chat => {
- if (!chat.received && chat.msg === message.msg) {
- return createMessage({ ...chat, received: true })
- }
- return chat
- })
+ let messageMarked = false
+ const updated_chat_history = chat_history.map(chat => {
+ // Only mark the first matching unreceived message
+ if (!messageMarked && !chat.received && chat.msg === message.msg && chat.source === "user") {
+ messageMarked = true
+ return { ...chat, received: true }
+ }
+ return chat
+ })
setChatHistory(updated_chat_history)
}Better solution: If the WebSocket message includes a unique identifier, use that instead:
if (message.source === "user" && message.id) {
const updated_chat_history = chat_history.map(chat => {
if (!chat.received && chat.updated_at === message.id) {
return { ...chat, received: true }
}
return chat
})
setChatHistory(updated_chat_history)
}…implify the mapping of messages. Remove unnecessary slice operation and directly map chat history for improved performance.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
… integrating chat history management. Update createMessage function to include 'received' status and improve chat history filtering logic. Refactor imports for better organization.
Summary by CodeRabbit
Improvements
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.