From a564274ba277a834b8a3ab4c28b2c1022fd9521e Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Sat, 20 Apr 2024 12:33:09 +0200 Subject: [PATCH] FIX: messages are already reversed (#26692) This is reverting part of https://github.com/discourse/discourse/commit/08ff0bac297dede8144f83a0b0aa3fc530943bcf to only have the call on exit channel. This was causing incorrect unread update. I will refactor this in another commit. --- .../discourse/components/chat-channel.gjs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs index 62ca9e26c8c..63d6d239c41 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs @@ -416,12 +416,15 @@ export default class ChatChannel extends Component { } schedule("afterRender", () => { - const messages = this.scrollable.querySelectorAll( - ".chat-message-container" - ); - let lastFullyVisibleMessageNode = Array.from(messages) - .reverse() - .find((item) => checkMessageBottomVisibility(this.scrollable, item)); + let lastFullyVisibleMessageNode = null; + + this.scrollable + .querySelectorAll(".chat-message-container") + .forEach((item) => { + if (checkMessageBottomVisibility(this.scrollable, item)) { + lastFullyVisibleMessageNode = item; + } + }); if (!lastFullyVisibleMessageNode) { return;