Skip to content

added solution#209

Open
Demtar23 wants to merge 3 commits into
mate-academy:masterfrom
Demtar23:develop
Open

added solution#209
Demtar23 wants to merge 3 commits into
mate-academy:masterfrom
Demtar23:develop

Conversation

@Demtar23
Copy link
Copy Markdown

@Demtar23 Demtar23 commented May 4, 2026

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

The implementation is missing two critical features that are explicitly required by the task: rename room and delete room functionality. The task description clearly states "create / rename / join / delete" rooms must be implemented, but only create and join are done. You need to add: 1) rename_room socket event handler in src/socket/socket.js to update room names and notify clients, 2) delete_room socket event handler to remove rooms from src/state/rooms.js and notify clients, 3) corresponding UI buttons in client/index.html and click handlers in client/main.js for both operations. These are not optional features—they are explicitly part of the requirements checklist.


✨ 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 client/main.js
Comment on lines +1 to +16
/* eslint-disable no-undef */
/* eslint-disable no-console */

const socket = io('http://localhost:3000');

const input = document.getElementById('input');
const btn = document.getElementById('send');
const messages = document.getElementById('messages');
const roomsDiv = document.getElementById('rooms');
const roomInput = document.getElementById('roomInput');
const createRoomBtn = document.getElementById('createRoom');

let username = localStorage.getItem('username');
let currentRoom = 'general';

function addRoom(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.

The requirements specify 'create / rename / delete' rooms, but only room creation is implemented. Rename and delete room UI elements and functionality are missing from the frontend.

Comment thread client/main.js
Comment on lines +21 to +79
button.addEventListener('click', () => {
socket.emit('join_room', name);
currentRoom = name;

messages.innerHTML = '';
});

roomsDiv.appendChild(button);
}

if (!username) {
username = prompt('Enter username');
localStorage.setItem('username', username);
}

socket.emit('set_username', username);

socket.on('connect', () => {
console.log('Connected:', socket.id);

socket.emit('join_room', 'general');
currentRoom = 'general';

messages.innerHTML = '';

addRoom('general');
});

socket.on('message', (data) => {
const div = document.createElement('div');

const time = new Date(data.time).toLocaleString();

div.textContent = `${data.author} [${time}]: ${data.text}`;
messages.appendChild(div);
});

socket.on('room_history', (mgss) => {
mgss.forEach((msg) => {
const div = document.createElement('div');

const time = new Date(msg.time).toLocaleTimeString();

div.textContent = `${msg.author} [${time}]: ${msg.text}`;

messages.appendChild(div);
});
});

socket.on('room_created', (roomName) => {
addRoom(roomName);
});

btn.addEventListener('click', () => {
const text = input.value;

if (!text) {
return;
}
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 specify 'create / rename / delete' rooms, but only create_room event is handled. Missing: rename_room and delete_room event handlers on the server.

Comment thread client/main.js
Comment on lines +90 to +104

createRoomBtn.addEventListener('click', () => {
const roomName = roomInput.value.trim();

if (!roomName) {
return;
}

socket.emit('create_room', roomName);
socket.emit('join_room', roomName);

currentRoom = roomName;

messages.innerHTML = '';
roomInput.value = '';
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 specify 'create / rename / delete' rooms, but only createRoom button exists. Missing UI buttons for renaming and deleting rooms.

Comment thread client/index.html
Comment on lines +11 to +16
<div>
<h3>Rooms</h3>

<div id="rooms"></div>
<input id="roomInput" placeholder="room name" />
<button id="createRoom">Create</button>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing 'rename room' functionality. The task requires 'create / rename / join / delete' rooms. There's no UI element or socket event handler for renaming rooms.

Comment thread client/index.html
Comment on lines +11 to +16
<div>
<h3>Rooms</h3>

<div id="rooms"></div>
<input id="roomInput" placeholder="room name" />
<button id="createRoom">Create</button>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing 'delete room' functionality. The task requires 'create / rename / join / delete' rooms. There's no UI element or socket event handler for deleting rooms.

Comment thread src/socket/socket.js
Comment on lines +34 to +81

socket.on('join_room', (roomName) => {
if (!roomName) {
return;
}

if (!rooms[roomName]) {
rooms[roomName] = {
messages: [],
};
}

socket.rooms.forEach((room) => {
if (room !== socket.id) {
socket.leave(room);
}
});

socket.join(roomName);

console.log('User joined room:', roomName);

socket.emit('room_history', rooms[roomName].messages);
});

socket.on('message', (data) => {
const room = data.room || 'general';

if (!rooms[room]) {
return;
}

const message = {
text: data.text,
author: data.author,
time: data.time,
};

rooms[room].messages.push(message);

io.to(room).emit('message', message);
});

socket.on('disconnect', () => {
console.log('User disconnected:', socket.id);

delete users[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.

Missing rename_room socket event handler. The task requires implementing 'rename rooms' functionality. Need to add: socket.on('rename_room', (oldName, newName) => {...}) to update the room name in the rooms object.

Comment thread src/socket/socket.js
Comment on lines +34 to +81

socket.on('join_room', (roomName) => {
if (!roomName) {
return;
}

if (!rooms[roomName]) {
rooms[roomName] = {
messages: [],
};
}

socket.rooms.forEach((room) => {
if (room !== socket.id) {
socket.leave(room);
}
});

socket.join(roomName);

console.log('User joined room:', roomName);

socket.emit('room_history', rooms[roomName].messages);
});

socket.on('message', (data) => {
const room = data.room || 'general';

if (!rooms[room]) {
return;
}

const message = {
text: data.text,
author: data.author,
time: data.time,
};

rooms[room].messages.push(message);

io.to(room).emit('message', message);
});

socket.on('disconnect', () => {
console.log('User disconnected:', socket.id);

delete users[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.

Missing delete_room socket event handler. The task requires implementing 'delete rooms' functionality. Need to add: socket.on('delete_room', (roomName) => {...}) to remove the room and notify clients.

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

There's a critical socket event name mismatch in client/main.js line 94 where socket.emit('join-room', newName) uses a hyphen, but the server socket handler listens for 'join_room' with an underscore. This breaks the room rename functionality—when a user renames a room, the client fails to properly join the renamed room, preventing message delivery and history loading for that room. The fix is straightforward: change 'join-room' to 'join_room' to match the server's event listener. This same issue appears in src/socket/socket.js where it's emitting the hyphenated version instead of the underscore version that the server expects. All other features are properly implemented, but this bug must be fixed before the rename room functionality can work correctly.


✨ 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 client/main.js
}

messages.innerHTML = '';

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 socket event name uses a hyphen ('join-room') but the server listens for 'join_room' with an underscore. The client won't properly join the renamed room after renaming, breaking message delivery. Change 'join-room' to 'join_room' to match the server handler.

Comment thread src/socket/socket.js
if (clientSocket) {
clientSocket.leave(oldName);
clientSocket.join(newName);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Event name mismatch: server listens for join_room (underscore) but this emits join-room (hyphen). After a room rename, the client won't properly load the room history. Change join-room to join_room.

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

Your chat application is working correctly and meets all requirements. The critical socket event naming issue has been resolved - all files now consistently use join_room with an underscore. You've successfully implemented username handling with localStorage persistence, message display with author/time/text formatting, and complete room management (create/rename/join/delete). The room history feature for new users is also working properly. Great job on ensuring consistency between client and server socket event handlers!


✨ 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