Skip to content

added#178

Open
MaksOther wants to merge 3 commits intomate-academy:masterfrom
MaksOther:develop
Open

added#178
MaksOther wants to merge 3 commits intomate-academy:masterfrom
MaksOther:develop

Conversation

@MaksOther
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

Great work setting up the server with Express and WebSockets! This is a solid foundation for a real-time application. However, this submission requires changes because several key features from the requirements are missing.

Here are the main points to address:

  • Missing Message Author: All messages, whether sent via HTTP POST or WebSocket, must include an author field. The server needs to be updated to receive and store the author's name with each message.
  • No Message History for New Users: When a new user connects, they should receive all previous messages for the room they join. Currently, a new client only sees messages sent after they've connected.
  • Missing Room Functionality: The application lacks the concept of chat rooms. The core functionality to create, rename, join, and delete rooms needs to be implemented.

✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

src/index.js Outdated
Comment on lines +20 to +23
const message = {
text,
time: new Date(),
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The requirements state that all messages must have an author, time, and text. This message object is missing the author. The server needs to receive the author's name from the client and include it here.

src/index.js Outdated
Comment on lines +31 to +33
emmiter.once('message', (message) => {
res.status(200).send(messages);
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This endpoint uses long polling by waiting for a 'message' event. For a user to retrieve the message history, it would be better to send the messages array immediately. The current implementation forces the client to wait for a new message to be sent before it can get any of the previous ones.

src/index.js Outdated

const wss = new WebSocketServer({ server });

wss.on('connection', (connection) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

One of the requirements is that a new user should see all previous messages. When a new client connects, you should send them the existing messages array. Currently, a new client will only see messages sent after they've connected.

src/index.js Outdated
Comment on lines +44 to +47
const message = {
text: text.toString(),
time: new Date(),
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Similar to the POST endpoint, messages received via WebSocket are also missing an author. The requirements state that all messages must include an author. The data received from the client should likely be a JSON string containing both the text and the author.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

Excellent progress on the chat server! You've successfully implemented all the required HTTP endpoints for managing rooms. However, some changes are needed in the WebSocket implementation to fix a couple of critical issues.

First, the connection.on('room_join', ...) event handler will not work as intended because the ws library handles all incoming data through the 'message' event. You'll need to move your room-joining logic inside the connection.on('message', ...) handler and parse the incoming message to determine the user's intent.

Second, when a room is renamed or deleted via the HTTP API, the connected WebSocket clients are not updated. This leaves them in a stale state, connected to a room that no longer exists, and they will stop receiving messages. You need to find a way to notify these clients of the change.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

src/index.js Outdated
Comment on lines +55 to +56
rooms[newName] = rooms[name];
delete rooms[name];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When a room is renamed, you should also update the room property for all connected WebSocket clients that are currently in that room. Otherwise, they will be stuck in a room that no longer exists and won't receive new messages.


app.delete('/rooms/:name', (req, res) => {
const { name } = req.params;
delete rooms[name];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When a room is deleted, what happens to the users currently in it? Their client.room property will refer to a room that no longer exists. Consider notifying these clients or moving them to a default room.

src/index.js Outdated
Comment on lines +96 to +101
connection.on('room_join', (room) => {
connection.room = room;
if (rooms[room]) {
connection.send(JSON.stringify({ history: rooms[room] }));
}
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This room_join event handler will not be triggered by messages sent from the client. All incoming data from a WebSocket client triggers the 'message' event. You need to handle different types of client requests (like joining a room vs. sending a message) inside the 'message' event handler, for example by checking a type property in the JSON payload.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

Great job addressing the feedback from the previous review! The WebSocket logic for joining rooms and notifying clients about deleted rooms is now working correctly.

The only missing piece is the ability to rename a room, as required by the task description. To implement this, you could add a PUT or PATCH endpoint like /rooms/:name.

I am approving your solution as an educational override to help you progress. You've built a solid foundation here, keep up the excellent work!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

ensureRoom(name);
res.status(201).send({ name });
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

According to the task description, you need to implement the ability to 'create / rename / join / delete' rooms. The functionality to rename a room is missing. You should add an endpoint here, for example, PUT /rooms/:name, to handle renaming.

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