From 4038c44f9a65cc5c1474e45ae656b62192901ee5 Mon Sep 17 00:00:00 2001 From: WBHarry <89362246+WBHarry@users.noreply.github.com> Date: Tue, 19 Aug 2025 13:03:16 +0200 Subject: [PATCH] [Fix] 987 - Auto Expand Bottom Chat (#1010) * If the last message in the chatlog is updated, scroll to bottom of chatlog * Cleaned up with ui.chat methods --- module/documents/chatMessage.mjs | 47 ++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/module/documents/chatMessage.mjs b/module/documents/chatMessage.mjs index e36c1df3..79449bc0 100644 --- a/module/documents/chatMessage.mjs +++ b/module/documents/chatMessage.mjs @@ -43,6 +43,18 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage { return super._preDelete(options, user); } + /** @inheritDoc */ + _onUpdate(changes, options, userId) { + super._onUpdate(changes, options, userId); + + const lastMessage = Array.from(game.messages).sort((a, b) => b.timestamp - a.timestamp)[0]; + if (lastMessage.id === this.id && ui.chat.isAtBottom) { + setTimeout(() => { + ui.chat.scrollBottom(); + }, 5); + } + } + enrichChatMessage(html) { const elements = html.querySelectorAll('[data-perm-id]'); elements.forEach(e => { @@ -55,7 +67,7 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage { }); if (this.isContentVisible) { - if(this.type === 'dualityRoll') { + if (this.type === 'dualityRoll') { html.classList.add('duality'); switch (this.system.roll?.result?.duality) { case 1: @@ -70,27 +82,28 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage { } } - const autoExpandRoll = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance).expandRollMessage, - rollSections = html.querySelectorAll(".roll-part"), - itemDesc = html.querySelector(".domain-card-move"); + const autoExpandRoll = game.settings.get( + CONFIG.DH.id, + CONFIG.DH.SETTINGS.gameSettings.appearance + ).expandRollMessage, + rollSections = html.querySelectorAll('.roll-part'), + itemDesc = html.querySelector('.domain-card-move'); rollSections.forEach(s => { - if(s.classList.contains("roll-section")) { + if (s.classList.contains('roll-section')) { const toExpand = s.querySelector('[data-action="expandRoll"]'); - toExpand.classList.toggle("expanded", autoExpandRoll.roll); - } else if(s.classList.contains("damage-section")) - s.classList.toggle("expanded", autoExpandRoll.damage); - else if(s.classList.contains("target-section")) - s.classList.toggle("expanded", autoExpandRoll.target); + toExpand.classList.toggle('expanded', autoExpandRoll.roll); + } else if (s.classList.contains('damage-section')) + s.classList.toggle('expanded', autoExpandRoll.damage); + else if (s.classList.contains('target-section')) s.classList.toggle('expanded', autoExpandRoll.target); }); - if(itemDesc && autoExpandRoll.desc) - itemDesc.setAttribute("open", ""); + if (itemDesc && autoExpandRoll.desc) itemDesc.setAttribute('open', ''); } - - if(!game.user.isGM) { - const applyButtons = html.querySelector(".apply-buttons"); + + if (!game.user.isGM) { + const applyButtons = html.querySelector('.apply-buttons'); applyButtons?.remove(); - if(!this.isAuthor && !this.speakerActor?.isOwner) { - const buttons = html.querySelectorAll(".ability-card-footer > .ability-use-button"); + if (!this.isAuthor && !this.speakerActor?.isOwner) { + const buttons = html.querySelectorAll('.ability-card-footer > .ability-use-button'); buttons.forEach(b => b.remove()); } }