Now we're going to fix createLocationMessage. You're going to want to find the user just like we do above, incase of createMessage. If there is a user you're going to want to emit the location to just people in the same room. Instead of providing Admin as the name you're also going to want to use the user's real name. We need to make sure it still gets sent to users in the same room and make sure it does not get sent to users in other rooms.
To do this one, I am going to start by fetching the user since we are going to need to use the information on that object. We're going to make a variable user calling users.getUser, and we're going to pass in that socket ID, socket.id. This is identical to the line we used above in createMesssage. Now we only want to emit a message if we do find a user, so I'm going to check if the user object exists. If it does, we can take io.emit line, cut it out, and copy it inside theĀ if statement. If it does exist, we are going to emit newLocationMessage:
if(user){
io.emit('newLocationMessage', generateLocationMessage('Admin', coords.latitude, coords.longitude));
}
Now we do still need to emit it to just a specific room by adding on a call to to and passing in the room name, user.room stores that information, and last but not least we do want to update the name. Instead of sending the static Admin name, we're going to use the user's real name, user.name:
io.to(user.room).emit('newLocationMessage', generateLocationMessage(user.name, coords.latitude, coords.longitude));
With this in place createLocationMessage is now wired up to be private and to send across the correct information. Over inside Chrome, I'm going to go through my tabs one at a time giving them a refresh, and on the second tab I am going to be sending the location. This is going to take just a couple of seconds to actually fetch it, and I see it right there with the name showing up correct:

We have Andrew and we have a link to view the location inside of Google Maps. Now if I go to the second tab, the user who is also connected to The Office Fans, I see the exact same location message:

If I go to the first one, you can see that Jen does not have access to that message because she's in a different room:

She can always share her location with anybody in her room, that happens to be nobody, this message is not going to show up anywhere because no one else is connected to LOTR.
With that in place we are now done, our messages are private, they're only going to be visible to folks in the same room. Let's go ahead and wrap this one up by committing our changes.