Skip to content

chat-issues-01 - #28

Merged
hey-Zayn merged 1 commit into
mainfrom
Live-0
Mar 25, 2026
Merged

chat-issues-01#28
hey-Zayn merged 1 commit into
mainfrom
Live-0

Conversation

@hey-Zayn

@hey-Zayn hey-Zayn commented Mar 25, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added automatic scrolling to the latest message in conversations.
    • Implemented real-time message polling to keep chat updated.
  • Bug Fixes

    • Enhanced message input validation to properly trim whitespace.
    • Improved error handling with on-screen notifications for failed operations.
  • Improvements

    • Message sending now requires user authentication.

@vercel

vercel Bot commented Mar 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
music-app Building Building Preview, Comment Mar 25, 2026 9:17pm
music-app-9r1o Ready Ready Preview, Comment Mar 25, 2026 9:17pm

@coderabbitai

coderabbitai Bot commented Mar 25, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 42160646-b4cf-4234-bd09-1a4d4c120b13

📥 Commits

Reviewing files that changed from the base of the PR and between 0c24259 and bfdcaad.

📒 Files selected for processing (5)
  • backend/src/Database/connection.js
  • backend/src/routes/message.route.js
  • frontend/src/pages/chat/components/MessageInput.tsx
  • frontend/src/pages/chat/page/ChatPage.tsx
  • frontend/src/store/useChatStore.tsx

📝 Walkthrough

Walkthrough

These changes add authentication to message sending via middleware, implement message polling with HTTP requests, and fix a typo in the chat store. The frontend now uses async message sending with improved input validation and automatic message list scrolling. Socket event handling was refactored for message deduplication.

Changes

Cohort / File(s) Summary
Backend Setup
backend/src/Database/connection.js, backend/src/routes/message.route.js
Whitespace formatting applied to connection setup; added protectRoute middleware to the /send POST route for authenticated message access control.
Chat Store Logic
frontend/src/store/useChatStore.tsx
Replaced synchronous sendMessge() with async sendMessage() using HTTP POST requests; added polling mechanism with startPolling() and stopPolling() methods; refactored socket event handlers with shared deduplication logic and improved message sorting by createdAt.
Chat UI Components
frontend/src/pages/chat/components/MessageInput.tsx, frontend/src/pages/chat/page/ChatPage.tsx
Fixed sendMessge typo; made handleSend() async and added message trimming validation; integrated polling control into conversation-change effect; added auto-scroll behavior to message list via scrollRef; updated imports and removed commented code.

Sequence Diagram

sequenceDiagram
    participant User as User<br/>(Client)
    participant UI as MessageInput<br/>(Component)
    participant Store as useChatStore<br/>(State)
    participant API as Backend API
    participant Polling as Polling<br/>(Interval)

    User->>UI: Type & send message
    UI->>Store: handleSend() → sendMessage(receiverId, content)
    Store->>API: POST /messages/send<br/>(with protectRoute)
    API-->>Store: Message created response
    Store->>Store: Insert message, dedupe by _id,<br/>sort by createdAt
    UI-->>User: Display message in list
    
    Note over Store,Polling: Polling Flow
    Store->>Polling: startPolling(userId)
    activate Polling
    loop Every 4 seconds
        Polling->>API: GET messages for userId
        API-->>Polling: Fetch messages
        Polling->>Store: Update message list<br/>(dedupe, sort)
        Store->>UI: Re-render messages
    end
    User->>UI: Switch conversation
    UI->>Polling: stopPolling()
    deactivate Polling
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 Hop hop, messages now flow secure and fast,
Polling ticks in time while auth stands steadfast,
No more typos hiding in the store,
Dedup and scroll—what could we ask for more?

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch Live-0

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.

@hey-Zayn
hey-Zayn merged commit 35f29fb into main Mar 25, 2026
5 of 6 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Mar 29, 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.

1 participant