Skip to content

Commit

Permalink
qol: tgchat lag fix caused by chat spam. (#6351)
Browse files Browse the repository at this point in the history
qol: tgchat lag fix
  • Loading branch information
dageavtobusnick authored Jan 12, 2025
1 parent 1ac743a commit 0c62134
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 45 deletions.
19 changes: 9 additions & 10 deletions tgui/packages/tgui-panel/chat/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ const updateMessageBadge = (message) => {
const foundBadge = node.querySelector('.Chat__badge');
const badge = foundBadge || document.createElement('div');
badge.textContent = times;
badge.className = classes(['Chat__badge', 'Chat__badge--animate']);
requestAnimationFrame(() => {
badge.className = 'Chat__badge';
});
badge.className = 'Chat__badge';

if (!foundBadge) {
node.appendChild(badge);
}
Expand Down Expand Up @@ -296,11 +294,7 @@ class ChatRenderer {
}
}

getCombinableMessage(predicate) {
const now = Date.now();
const len = this.visibleMessages.length;
const from = len - 1;
const to = Math.max(0, len - COMBINE_MAX_MESSAGES);
getCombinableMessage(predicate, now, from, to) {
for (let i = from; i >= to; i--) {
const message = this.visibleMessages[i];
// prettier-ignore
Expand Down Expand Up @@ -335,10 +329,15 @@ class ChatRenderer {
const fragment = document.createDocumentFragment();
const countByType = {};
let node;

const len = this.visibleMessages.length;
const from = len - 1;
const to = Math.max(0, len - COMBINE_MAX_MESSAGES);

for (let payload of batch) {
const message = createMessage(payload);
// Combine messages
const combinable = this.getCombinableMessage(message);
const combinable = this.getCombinableMessage(message, now, from, to);
if (combinable) {
combinable.times = (combinable.times || 1) + 1;
updateMessageBadge(combinable);
Expand Down
70 changes: 35 additions & 35 deletions tgui/public/tgui-panel.bundle.js

Large diffs are not rendered by default.

0 comments on commit 0c62134

Please sign in to comment.