Skip to content

add task solution#97

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

add task solution#97
pakhomovalex wants to merge 2 commits into
mate-academy:masterfrom
pakhomovalex:develop

Conversation

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/index.js
messageTime
};

io.emit('message', message);
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 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.

Comment thread src/index.js

socket.emit('checkRoomResult', { roomId, isMember: true });

socket.to(roomId).emit('message', `Пользователь ${socket.id} присоединился`);
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 '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.

Comment thread src/index.js Outdated
console.log(error, 'error');
}

socket.to(roomId).emit('message', `Пользователь ${socket.id} присоединился`);
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: 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.

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! 🎉 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! ✨

Footnotes

  1. Rate AI review example

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