From cf8865d9706ca4272eea48e77a55e329a131b0f7 Mon Sep 17 00:00:00 2001 From: Marshall Polaris Date: Thu, 10 Jan 2019 14:33:59 -0800 Subject: [PATCH] Make optional author override on incoming chat --- src/hub.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/hub.js b/src/hub.js index 91db89e8d0..3a0c082ee8 100644 --- a/src/hub.js +++ b/src/hub.js @@ -649,12 +649,22 @@ document.addEventListener("DOMContentLoaded", async () => { NAF.connection.adapter.onData(data); }); - hubPhxChannel.on("message", ({ session_id, type, body }) => { - const userInfo = hubPhxPresence.state[session_id]; - if (!userInfo) return; + hubPhxChannel.on("message", ({ session_id, type, body, from }) => { + const getAuthor = () => { + const userInfo = hubPhxPresence.state[session_id]; + if (from) { + return from; + } else if (userInfo) { + return userInfo.metas[0].profile.displayName; + } else { + return "Mystery user"; + } + }; + + const name = getAuthor(); const maySpawn = scene.is("entered"); - const incomingMessage = { name: userInfo.metas[0].profile.displayName, type, body, maySpawn }; + const incomingMessage = { name, type, body, maySpawn }; if (scene.is("vr-mode")) { createInWorldLogMessage(incomingMessage);