Skip to content

Commit

Permalink
Make sure there is at least 150 history messages in the message array.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitchdev committed Dec 7, 2024
1 parent 2380b98 commit 478bbed
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions assets/chat/js/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,26 @@ class ChatWindow extends EventEmitter {
remove.forEach((element) => {
element.remove();
});

this.messages = this.messages.slice(lines.length - this.maxlines);
}

let clientMessages = 0;
this.messages = this.messages
.reverse()
.filter((message, index) => {
if (clientOnlyMessages.includes(message.type)) {
clientMessages += 1;
// remove client only messages if above maxlines
if (index >= this.maxlines) {
return false;
}
// remove history message if above maxlines/maxhistory + the clientMessages
} else if (index >= Math.max(this.maxlines, 150) + clientMessages) {
return false;
}

return true;
})
.reverse();
}
}

Expand Down

0 comments on commit 478bbed

Please sign in to comment.