From 86301ebf93f38c6562e7cae415069a182ea14da1 Mon Sep 17 00:00:00 2001 From: Charsy89 Date: Thu, 28 May 2020 09:45:52 -0600 Subject: [PATCH] Name only updates in one room --- src/Message.js | 4 ++-- src/Room.js | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Message.js b/src/Message.js index b8b79d9..54cd4db 100644 --- a/src/Message.js +++ b/src/Message.js @@ -112,7 +112,7 @@ module.exports = (cl) => { dbentry.name = msg.set.name; user.updatedb(); cl.server.rooms.forEach((room) => { - room.updateParticipant(cl.participantId, { + room.updateParticipant(cl.user._id, { name: msg.set.name }); }) @@ -155,7 +155,7 @@ module.exports = (cl) => { dbentry.color = msg.color; //user.updatedb(); cl.server.rooms.forEach((room) => { - room.updateParticipant(usr.participantId, { + room.updateParticipant(usr.user._id, { color: msg.color }); }) diff --git a/src/Room.js b/src/Room.js index f6f6520..7616c88 100644 --- a/src/Room.js +++ b/src/Room.js @@ -97,11 +97,14 @@ class Room extends EventEmitter { this.server.updateRoom(this.fetchData()); } updateParticipant(pid, options) { - let p = this.ppl.get(pid); - if (!p) return; - options.name ? this.ppl.get(pid).user.name = options.name : {}; - options._id ? this.ppl.get(pid).user._id = options._id : {}; - options.color ? this.ppl.get(pid).user.color = options.color : {}; + let p = null; + Array.from(this.ppl).map(rpg => { + if(e[1].user._id == pid) p = e[1]; + }); + if (p == null) return; + options.name ? p.user.name = options.name : {}; + options._id ? p.user._id = options._id : {}; + options.color ? p.user.color = options.color : {}; this.connections.filter((ofo) => ofo.participantId == p.participantId).forEach((usr) => { options.name ? usr.user.name = options.name : {}; options._id ? usr.user._id = options._id : {};