Skip to content

Implement one-to-one real-time chat using Socket.IO#1382

Open
gaurav123-4 wants to merge 3 commits intoCode-A2Z:mainfrom
gaurav123-4:gaurav
Open

Implement one-to-one real-time chat using Socket.IO#1382
gaurav123-4 wants to merge 3 commits intoCode-A2Z:mainfrom
gaurav123-4:gaurav

Conversation

@gaurav123-4
Copy link

Pull Requests Review Criteria

Caution

PRs that fail to meet these review standards will be automatically flagged and may be rejected by maintainers.

  • Filled out this PR template properly
  • Did not commit directly to main
  • Limited commits (max 3–4 unless permitted by Admin/Mentors)
  • Added comments in complex parts of code

Closes: #1380

Describe the add-ons or changes you've made 📃

Implementation Summary
Files Created/Updated:
Database Schema & Model:
src/schemas/message.schema.js - Message schema with sender/receiver, read status, and indexes
src/models/message.model.js - Message model
Updated src/constants/db.js - Added MESSAGES collection
Socket.IO Server:
src/config/socket.io.js - Socket.IO server with:
JWT authentication middleware
Connection management
Real-time event handlers
REST API Controllers:
src/controllers/chat/get-messages.js - Get conversation messages
src/controllers/chat/get-conversations.js - Get list of conversations
Routes:
Updated src/routes/api/chat.routes.js - Added endpoints for messages and conversations
Server Integration:
Updated index.js - Initialize Socket.IO with HTTP server
Updated src/stores/online-users.js - Added removePresence function
Updated package.json - Added socket.io dependency
Socket.IO Events:
Client → Server:
message:send - Send a message to another user
typing:start - Indicate user is typing
typing:stop - Stop typing indicator
message:read - Mark messages as read
Server → Client:
message:sent - Confirmation message was sent
message:receive - Receive a new message
message:read - Notification that messages were read
typing:start - User started typing
typing:stop - User stopped typing
user:online - User came online
user:offline - User went offline
message:error - Error occurred
REST API Endpoints:
GET /api/chat/conversations - Get all conversations for current user
GET /api/chat/messages/:userId - Get messages with a specific user (supports pagination)

Screenshots 📷

Note to reviewers (Optional) 📄

@vercel
Copy link

vercel bot commented Feb 13, 2026

@gaurav123-4 is attempting to deploy a commit to the avdheshvarshney's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link

Thank you for submitting your pull request! We'll review it as soon as possible. For further communication, join our discord server https://discord.gg/tSqtvHUJzE.

@vercel
Copy link

vercel bot commented Feb 13, 2026

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

Project Deployment Actions Updated (UTC)
code-a2z Ready Ready Preview, Comment Feb 14, 2026 5:51pm
code-a2z-server Ready Ready Preview, Comment Feb 14, 2026 5:51pm

@Avdhesh-Varshney
Copy link
Collaborator

Avdhesh-Varshney commented Feb 13, 2026

image

@gaurav123-4 Please check your FE deployment has failed.

Copy link
Collaborator

@Avdhesh-Varshney Avdhesh-Varshney left a comment

Choose a reason for hiding this comment

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

@gaurav123-4 Great Work.

Display all the registered users but on later will display the status on user on avatar like a green dot (for online users) otherwise empty dot (for offline users).

Please share me a working demo video of this whole current state of the feature.

@@ -0,0 +1,4 @@
export const CHATS_SIDEBAR_WIDTH = 280;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Increase width to 300px

Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove changes from this file

@Avdhesh-Varshney
Copy link
Collaborator

@gaurav123-4 You have forget to remove the lock from this icon.
image

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.

Implement one-to-one real-time chat using Socket.IO

2 participants