Skip to content

Enhance ShikshalokamChat and ShikshalokamVoiceBasedChat components by… - #215

Merged
Vinod-V3 merged 2 commits into
ELEVATE-Project:release-1.0.4from
VishnuKrishnathu:feature/ip-socket
Dec 16, 2025
Merged

Enhance ShikshalokamChat and ShikshalokamVoiceBasedChat components by…#215
Vinod-V3 merged 2 commits into
ELEVATE-Project:release-1.0.4from
VishnuKrishnathu:feature/ip-socket

Conversation

@VishnuKrishnathu

@VishnuKrishnathu VishnuKrishnathu commented Dec 15, 2025

Copy link
Copy Markdown

… 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

    • Message items now track and surface a "received" status for clearer delivery visibility.
    • Chat history is cleaned and persisted to retain only confirmed/received messages.
    • Loading and initialization flows improved (including IP fetch and language setup) for more reliable startup behavior.
  • Bug Fixes

    • Ensured bot and streamed messages are marked received promptly to reduce ordering/visibility issues.

✏️ Tip: You can customize this high-level summary in your review settings.

… integrating chat history management. Update createMessage function to include 'received' status and improve chat history filtering logic. Refactor imports for better organization.
@coderabbitai

coderabbitai Bot commented Dec 15, 2025

Copy link
Copy Markdown

Walkthrough

Adds a received flag to messages, marks user/bot messages as received on WebSocket/events, and introduces chat history persistence via useSmartChatStorage plus IP-fetch status wiring during chat initialization.

Changes

Cohort / File(s) Change Summary
Message factory
src/pages/interview-voice/index.js
createMessage now accepts received (default false) and includes received in the returned message object.
Voice-chat WebSocket handling
src/pages/ShikshalokamVoiceChat/voice-chat.js
On incoming WS messages, mark matching user chat entries as received; add bot intro and streamed bot messages with received: true; adjust chatHistory update ordering/batching.
Chat storage & init / IP state
src/pages/shikshalokamChat.js
Integrates useSmartChatStorage for chatHistory; on mount filters/stores only received messages; reads/writes ipFetched from storage and ties loading/initialization to IP fetch status; imports ROUTES and ShikshalokamVoiceBasedChat for setup flow.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant UI as Client UI
participant WS as WebSocket Server
participant Store as useSmartChatStorage
participant Bot as Bot/Streamer
UI->>WS: send user message
WS-->>UI: ack / echo message
note right of UI: On WS receive match -> mark user message received
UI->>Store: update chatHistory (user received)
Bot->>UI: send intro or streamed bot message
UI->>Store: append bot message with received:true
note over Store: chatHistory persists only received messages on mount

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review focus:
    • Verify received propagation from createMessage to all callers.
    • Confirm WS matching logic for marking user messages as received handles duplicates/order.
    • Validate useSmartChatStorage filtering and lifecycle interactions with IP fetch state.

Possibly related PRs

Suggested reviewers

  • Vinod-V3

Poem

🐇 I scurried through sockets light and fleet,

marking each tiny message "received" so neat.
Stored the hops where echoes rest,
IP fetched — the chat's at best.
🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title is incomplete and vague; it uses ellipsis ('by…') and does not convey the complete main change clearly. Complete the title to clearly state the main change, e.g., 'Add received status tracking and chat history management to ShikshalokamChat components'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9d2b9f3 and 097b7f6.

📒 Files selected for processing (1)
  • src/pages/ShikshalokamVoiceChat/voice-chat.js (3 hunks)
🔇 Additional comments (2)
src/pages/ShikshalokamVoiceChat/voice-chat.js (2)

741-746: LGTM: Intro message correctly marked as received.

Marking the intro message with received: true when loading from history is appropriate since it represents an already-delivered message.


843-850: LGTM: Bot messages correctly marked as received.

Setting received: true for bot messages is appropriate since these messages originate from the server and are inherently "received" when created locally.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@VishnuKrishnathu

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 15, 2025

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 19fc369 and 9d2b9f3.

📒 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 received parameter addition is well-implemented with an appropriate default value of false for 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: true for 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: true when 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 ipFetched tracking and chatHistory from useSmartChatStorage correctly 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 false before starting the async setup
  • Set to true in the finally block 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.js lines 278-281 where unreceived status is toggled when the server responds)
  • Messages created with received: false are 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.

Comment on lines +277 to +286
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)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fix message matching logic to prevent marking multiple messages as received.

The current logic has several issues:

  1. 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
  2. Text-based matching is fragile: Messages should be matched by unique identifiers (e.g., timestamp, server ID, or client-generated UUID) rather than content
  3. 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.
@VishnuKrishnathu

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 16, 2025

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Vinod-V3
Vinod-V3 merged commit e1d4d1f into ELEVATE-Project:release-1.0.4 Dec 16, 2025
1 check passed
@coderabbitai coderabbitai Bot mentioned this pull request Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants