add task solution#97
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Thank you for your work on this chat server! There are a couple of critical issues that need to be addressed before the PR can be approved. First, new messages are not being added to the messages array, so message history is not maintained for users joining a room later—this is a core requirement. Second, the 'message' event is emitted twice when a user joins a room, leading to duplicate notifications for everyone in the room. Please fix these issues to ensure correct functionality. Once resolved, your implementation will be much stronger! 😊 If you need help, check out the Socket.IO documentation on rooms and message history. Keep going—you’re almost there!
✨ 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
| messageTime | ||
| }; | ||
|
|
||
| io.emit('message', message); |
There was a problem hiding this comment.
Issue: The new message is emitted to all clients but is not added to the messages array. This means that when a client requests the message history (via 'getMessages'), the new message will not be included. You should add the new message to the messages array here to persist it.
|
|
||
| socket.emit('checkRoomResult', { roomId, isMember: true }); | ||
|
|
||
| socket.to(roomId).emit('message', `Пользователь ${socket.id} присоединился`); |
There was a problem hiding this comment.
Issue: The 'message' event is emitted to the room both inside the try block and again after the try-catch (line 71). This will result in duplicate notifications to the room when a user joins. You should only emit this event once.
| console.log(error, 'error'); | ||
| } | ||
|
|
||
| socket.to(roomId).emit('message', `Пользователь ${socket.id} присоединился`); |
There was a problem hiding this comment.
Issue: This line emits a 'message' event to the room after the same event was already emitted inside the try block (line 66). This will cause duplicate join notifications. Remove one of these lines to avoid duplicate messages.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job! 🎉 Your implementation meets all the core requirements: users can join rooms, messages are broadcast correctly, message history is maintained, and there are no duplicate events or unnecessary files. Everything works as expected with no critical issues. Keep up the good work!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.