Volatile chat buffer for channel-only chats implemented.

This commit is contained in:
rainbow napkin 2025-06-11 08:27:56 -04:00
parent 8821b5cff9
commit 366df357b8
4 changed files with 27 additions and 4 deletions

View file

@ -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){

View file

@ -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){

View file

@ -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(){

View file

@ -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){