From de5268a41f13d6d25498e0615ae502febf84f4e8 Mon Sep 17 00:00:00 2001 From: rainbow napkin Date: Wed, 22 Apr 2026 12:34:49 -0400 Subject: [PATCH] Userlist colors persist accross other users' reconnects. --- www/js/channel/commandPreprocessor.js | 3 +- www/js/channel/userlist.js | 40 +++++++++++++++++++-------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/www/js/channel/commandPreprocessor.js b/www/js/channel/commandPreprocessor.js index af05cfe..1dbc218 100644 --- a/www/js/channel/commandPreprocessor.js +++ b/www/js/channel/commandPreprocessor.js @@ -269,7 +269,8 @@ class commandPreprocessor{ usernames:{ prefix: '', postfix: '', - cmds: injectPerms(Array.from(client.userList.colorMap.keys())) + //cmds: injectPerms(Array.from(client.userList.colorMap.keys())) + cmds: injectPerms(client.userList.getOnlineUserNames()) }, emotes:{ prefix:'[', diff --git a/www/js/channel/userlist.js b/www/js/channel/userlist.js index 5a4f24c..9edecb0 100644 --- a/www/js/channel/userlist.js +++ b/www/js/channel/userlist.js @@ -32,6 +32,12 @@ class userList{ * Click Dragger object for handling userlist resizes */ this.clickDragger = new canopyUXUtils.clickDragger("#chat-panel-users-drag-handle", "#chat-panel-users-div", true, this.client.chatBox.clickDragger); + + + /** + * List of currently connected users + */ + this.userList = []; /** * Userlist color array (Maps to css classes) @@ -46,7 +52,7 @@ class userList{ "userlist-color6"]; /** - * Map of usernames to assigned username color + * Map of connected and buffered usernames to assigned username color/flair */ this.colorMap = new Map(); @@ -58,7 +64,7 @@ class userList{ /** * userlist div */ - this.userList = document.querySelector("#chat-panel-users-list-div"); + this.userListDiv = document.querySelector("#chat-panel-users-list-div"); /** * user count label @@ -103,28 +109,28 @@ class userList{ updateList(list){ //Clear list and set user count this.userCount.textContent = list.length == 1 ? '1 User' : `${list.length} Users`; - this.userList.innerHTML = null; + this.userListDiv.innerHTML = null; - //create a new map - var newMap = new Map(); + //Set userlist array to received list + this.userList = list; //for each user list.forEach((user) => { //randomly pick a color var color = this.userColors[Math.floor(Math.random()*this.userColors.length)] - //if this user was in the previous colormap - if(this.colorMap.get(user.user) != null){ - //Override with previous color + //if this user wasn't in the previous colormap + if(this.colorMap.get(user.user) == null){ + //Store new randomly selected color + this.colorMap.set(user.user, color); + }else{ + //Use color from previous entry color = this.colorMap.get(user.user); } - newMap.set(user.user, color); this.renderUser(user, color); }); - this.colorMap = newMap; - //Make sure we're not cutting the ux off this.clickDragger.fixCutoff(); } @@ -168,7 +174,7 @@ class userList{ userSpan.addEventListener('click', renderContextMenu.bind(this)); userSpan.addEventListener('contextmenu', renderContextMenu.bind(this)); - this.userList.appendChild(userSpan); + this.userListDiv.appendChild(userSpan); function renderContextMenu(event){ //Setup menu map @@ -211,4 +217,14 @@ class userList{ } } + //returns list of strings containing all currently online users + getOnlineUserNames(){ + var names = []; + + for(let user of this.userList){ + names.push(user.user); + } + + return names; + } } \ No newline at end of file