Skip to content

Commit

Permalink
Refactor change_name event to include room ID and send system message
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne committed Feb 13, 2024
1 parent 8327adc commit 8508650
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 10 additions & 1 deletion backend/src/routes/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,19 @@ let userNames: { [key: string]: string } = {};

io.on("connection", (socket) => {
// changer de nom
socket.on("change_name", (newName: string) => {
socket.on("change_name", ({ newName, OldName, roomId }) => {
console.log("User changed name: ", newName);
userNames[socket.id] = newName;
socket.emit("name_changed", newName);

if (roomId) {
io.emit("receive_message", {
text: OldName + " change is name for " + newName,
socketId: "Kurama-chat",
roomId: roomId,
systemMessage: true,
});
}
});

// Clear les messages du chat
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/components/Chat/ChatFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ function ChatFooter({ roomId }: { roomId: string }) {
switch (command) {
case "nick":
const newName = args.join(" ");
socket?.emit("change_name", newName);
socket?.emit("change_name", {
OldName: localStorage.getItem("name"),
newName,
roomId,
});
break;
case "list":
socket.emit("list", args.join(" "));
Expand Down

0 comments on commit 8508650

Please sign in to comment.