From 1b9172a46964282151e40521a60b14a0b4ba4d2d Mon Sep 17 00:00:00 2001 From: vyneer Date: Mon, 11 Dec 2023 23:50:33 +0300 Subject: [PATCH] fix: error on trying to apply user tags to server broadcasts --- assets/chat/js/chat.js | 11 ++++++----- assets/chat/js/messages/ChatBroadcastMessage.js | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/assets/chat/js/chat.js b/assets/chat/js/chat.js index 54e10373..b0f39693 100644 --- a/assets/chat/js/chat.js +++ b/assets/chat/js/chat.js @@ -743,15 +743,15 @@ class Chat { message.slashme = message.message.substring(0, 4).toLowerCase() === '/me '; // check if this is the current users message - message.isown = message.user.username === this.user.username; + message.isown = message.user?.username === this.user.username; // get mentions from message message.mentioned = Chat.extractNicks(message.message).filter((a) => this.users.has(a.toLowerCase()), ); // set tagged state - message.tag = this.taggednicks.get(message.user.username); + message.tag = this.taggednicks.get(message.user?.username); // set tagged note - message.title = this.taggednotes.get(message.user.username) || ''; + message.title = this.taggednotes.get(message.user?.username) || ''; } // Populate highlight for this $message @@ -1266,8 +1266,9 @@ class Chat { ).into(this); } } else { - const user = - this.users.get(data.nick.toLowerCase()) ?? new ChatUser(data.user); + const user = data.nick + ? this.users.get(data.nick.toLowerCase()) ?? new ChatUser(data.user) + : null; MessageBuilder.broadcast(data.data, user, data.timestamp).into(this); } } diff --git a/assets/chat/js/messages/ChatBroadcastMessage.js b/assets/chat/js/messages/ChatBroadcastMessage.js index 6b358e01..2a69ed88 100644 --- a/assets/chat/js/messages/ChatBroadcastMessage.js +++ b/assets/chat/js/messages/ChatBroadcastMessage.js @@ -10,7 +10,7 @@ export default class ChatBroadcastMessage extends ChatEventMessage { } buildUserTemplate(chat = null) { - if (this.user.displayName !== '') { + if (this.user && this.user.displayName !== '') { const colorFlair = usernameColorFlair(chat.flairs, this.user); /** @type HTMLAnchorElement */