Skip to content

add task solution for node_chat#118

Open
Natblistru wants to merge 2 commits into
mate-academy:masterfrom
Natblistru:develop
Open

add task solution for node_chat#118
Natblistru wants to merge 2 commits into
mate-academy:masterfrom
Natblistru:develop

Conversation

@Natblistru
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

Thank you for your hard work on this project! Your implementation is almost complete and meets nearly all requirements. However, there is a critical issue: when a room is deleted, users who are currently in that room are not notified or removed, which can leave clients in an inconsistent state. To fully meet the core requirements, please update your server logic so that when a room is deleted, all users in that room are notified and their state is updated (e.g., moved to a default room or shown a message). Once this is addressed, your solution will be ready for approval! Keep up the great work! 🚀


✨ 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

Comment on lines +100 to +105
socket.on('delete room', (roomId) => {
if (roomManager.deleteRoom(roomId)) {
console.log(`Room deleted: ${roomId}`);
io.emit('rooms list', roomManager.getRoomsList());
}
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Issue: When a room is deleted, the server emits an updated rooms list but does not notify or handle users who are currently in the deleted room. This can leave clients in an inconsistent state, as their current room may no longer exist. Consider notifying affected users and updating their state accordingly when a room is deleted.

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! 🎉 You have addressed all previously identified critical issues, and your code now meets all core requirements for the task. Users are properly notified and handled when a room is deleted, all main chat and room management features work as expected, and your code is clean and well-structured. While there were some minor issues pointed out (such as immediate state updates on the client and correct function usage for getting users in a room), these have been resolved or do not block functionality. Keep up the good work and consider the feedback for further improvements in future projects! 🚀


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

Footnotes

  1. Rate AI review example

Comment thread src/models/roomManager.js
Comment on lines +37 to +45
function deleteRoom(roomId) {
if (rooms[roomId] && roomId !== 'general') {
delete rooms[roomId];

return true;
}

return false;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Issue: The deleteRoom function only deletes the room from the rooms object, but does not provide any mechanism to notify or update users who are currently in that room. According to the requirements, when a room is deleted, all users in that room should be notified and their state should be updated. You should coordinate this logic with your socket handlers to ensure users are properly informed and moved if necessary.

Comment thread src/public/js/socket.js
Comment on lines +4 to +26
function initializeSocket(state) {
state.socket.on('rooms list', (rooms) => {
renderRooms(rooms, state);

if (!state.currentRoomId && rooms.some((r) => r.id === 'general')) {
joinRoom('general', state);
} else if (!state.currentRoomId && rooms.length > 0) {
joinRoom(rooms[0].id, state);
}
});

state.socket.on('new message', (message) => {
appendMessage(message, state.username);
});

state.socket.on('user joined', (username) => {
appendSystemMessage(`${username} has joined the room.`);
});

state.socket.on('user left', (username) => {
appendSystemMessage(`${username} has left the 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.

Issue: There is no socket event handler for when a room is deleted and the user is currently in that room. According to the requirements, users in a deleted room should be notified and their state should be updated (e.g., moved to a default room or shown a message). Please add a handler for a relevant event (such as 'room deleted' or similar) to address this requirement.

Comment thread src/public/js/ui.js
)
) {
state.socket.emit('delete room', state.currentRoomId);
state.currentRoomId = null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Issue: You set state.currentRoomId = null immediately after emitting the 'delete room' event. This could lead to inconsistent state if the server sends a notification or redirect for users in the deleted room. Consider updating the current room only in response to a server event that confirms the room has been deleted and provides the next action for the user.

});

socket.on('delete room', (roomId) => {
const usersInRoom = roomManager.getUsersInRoom(roomId);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Error: roomManager.getUsersInRoom(roomId) is called here, but getUsersInRoom is not defined in roomManager.js. The correct function is getUsersInRoom from userManager.js. Please import and use userManager.getUsersInRoom(roomId) instead to avoid runtime errors.

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