From 366df357b863d064adba1176fdb41f43e167cdeb Mon Sep 17 00:00:00 2001 From: rainbow napkin Date: Wed, 11 Jun 2025 08:27:56 -0400 Subject: [PATCH] Volatile chat buffer for channel-only chats implemented. --- src/app/channel/activeChannel.js | 2 ++ src/app/channel/chatHandler.js | 18 +++++++++++++++--- src/app/channel/connectedUser.js | 5 ++++- www/js/channel/channel.js | 6 ++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/app/channel/activeChannel.js b/src/app/channel/activeChannel.js index 7539561..5e9ebd7 100644 --- a/src/app/channel/activeChannel.js +++ b/src/app/channel/activeChannel.js @@ -29,6 +29,8 @@ module.exports = class{ this.userList = new Map(); this.queue = new queue(server, chanDB, this); this.playlistHandler = new playlistHandler(server, chanDB, this); + //Define the chat buffer + this.chatBuffer = []; } async handleConnection(userDB, chanDB, socket){ diff --git a/src/app/channel/chatHandler.js b/src/app/channel/chatHandler.js index ad627f4..26dea9d 100644 --- a/src/app/channel/chatHandler.js +++ b/src/app/channel/chatHandler.js @@ -31,8 +31,8 @@ module.exports = class{ this.server = server; //Initialize command preprocessor this.commandPreprocessor = new commandPreprocessor(server, this) - //Define the chat buffer - this.chatBuffer = []; + //Max chat buffer size + this.chatBufferSize = 50; } defineListeners(socket){ @@ -135,7 +135,19 @@ module.exports = class{ } relayChatObject(chan, chat){ + //Send out chat this.server.io.in(chan).emit("chatMessage", chat); + + const channel = this.server.activeChannels.get(chan); + + //If chat buffer length is over mandated size + if(channel.chatBuffer.length >= this.chatBufferSize){ + //Take out oldest chat + channel.chatBuffer.shift(); + } + + //Add buffer to chat + channel.chatBuffer.push(chat); } relayPrivateChat(socket, user, flair, highLevel, msg, type, links){ @@ -147,7 +159,7 @@ module.exports = class{ } relayGlobalChat(user, flair, highLevel, msg, type = 'chat', links){ - this.relayGlobalChatObject("chatMessage", new chat(user, flair, highLevel, msg, type, links)); + this.relayGlobalChatObject(new chat(user, flair, highLevel, msg, type, links)); } relayGlobalChatObject(chat){ diff --git a/src/app/channel/connectedUser.js b/src/app/channel/connectedUser.js index cebc454..f7c3176 100644 --- a/src/app/channel/connectedUser.js +++ b/src/app/channel/connectedUser.js @@ -159,8 +159,11 @@ module.exports = class{ //Get schedule lock status const queueLock = this.channel.queue.locked; + //Get chat buffer + const chatBuffer = this.channel.chatBuffer; + //Send off the metadata to our user's clients - this.emit("clientMetadata", {user: userObj, flairList, queue, queueLock}); + this.emit("clientMetadata", {user: userObj, flairList, queue, queueLock, chatBuffer}); } async sendSiteEmotes(){ diff --git a/www/js/channel/channel.js b/www/js/channel/channel.js index c373e56..3f9df64 100644 --- a/www/js/channel/channel.js +++ b/www/js/channel/channel.js @@ -99,6 +99,12 @@ class channel{ //Store queue lock status this.queueLock = data.queueLock; + + //For each chat held in the chat buffer + for(let chat of data.chatBuffer){ + //Display the chat + this.chatBox.displayChat(chat); + } } setDefaults(force = false, processConfig = false){