A platform for community discussion. Free, open, simple.
FIX: correctly updates last read on scroll arrow click (#25838)
Joffrey JAFFEUX9e08b45f9b19
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjsindex 829cebb66b7..693dca0efb3 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs@@ -255,9 +255,10 @@ export default class ChatChannel extends Component {}@action- scrollToBottom() {+ async scrollToBottom() {this._ignoreNextScroll = true;- scrollListToBottom(this.scrollable);+ await scrollListToBottom(this.scrollable);+ this.debouncedUpdateLastReadMessage();}scrollToMessageId(messageId, options = {}) {diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-message.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-message.gjsindex 166b509b5c1..2159a44f756 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-message.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/chat-message.gjs@@ -520,6 +520,14 @@ export default class ChatMessage extends Component {(if @message.highlighted "-highlighted")(if @message.streaming "-streaming")(if (eq @message.user.id this.currentUser.id) "is-by-current-user")+ (if (eq @message.id this.currentUser.id) "is-by-current-user")+ (if+ (eq+ @message.id+ @message.channel.currentUserMembership.lastReadMessageId+ )+ "-last-read"+ )(if @message.staged "-staged" "-persisted")(if @message.processed "-processed" "-not-processed")(if this.hasActiveState "-active")diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjsindex 1a924fe1e35..effb3859a1f 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjs@@ -489,15 +489,15 @@ export default class ChatThread extends Component {}@action- scrollToBottom() {+ async scrollToBottom() {this._ignoreNextScroll = true;- scrollListToBottom(this.scrollable);+ await scrollListToBottom(this.scrollable);}@action- scrollToTop() {+ async scrollToTop() {this._ignoreNextScroll = true;- scrollListToTop(this.scrollable);+ await scrollListToTop(this.scrollable);}@actiondiff --git a/plugins/chat/assets/javascripts/discourse/lib/scroll-helpers.js b/plugins/chat/assets/javascripts/discourse/lib/scroll-helpers.jsindex f059be73646..e93d5c9e6af 100644--- a/plugins/chat/assets/javascripts/discourse/lib/scroll-helpers.js+++ b/plugins/chat/assets/javascripts/discourse/lib/scroll-helpers.js@@ -1,15 +1,21 @@-import { schedule } from "@ember/runloop";+import { next, schedule } from "@ember/runloop";import { stackingContextFix } from "discourse/plugins/chat/discourse/lib/chat-ios-hacks";-export function scrollListToBottom(list) {- stackingContextFix(list, () => {- list.scrollTo({ top: 0, behavior: "auto" });+export async function scrollListToBottom(list) {+ await new Promise((resolve) => {+ stackingContextFix(list, () => {+ list.scrollTo({ top: 0, behavior: "auto" });+ next(resolve);+ });});}-export function scrollListToTop(list) {- stackingContextFix(list, () => {- list.scrollTo({ top: -list.scrollHeight, behavior: "auto" });+export async function scrollListToTop(list) {+ await new Promise((resolve) => {+ stackingContextFix(list, () => {+ list.scrollTo({ top: -list.scrollHeight, behavior: "auto" });+ next(resolve);+ });});}diff --git a/plugins/chat/spec/system/chat_channel_spec.rb b/plugins/chat/spec/system/chat_channel_spec.rbindex 3983a90c1ff..858b8da85de 100644--- a/plugins/chat/spec/system/chat_channel_spec.rb+++ b/plugins/chat/spec/system/chat_channel_spec.rb@@ -141,6 +141,7 @@ RSpec.describe "Chat channel", type: :system doexpect(channel_page).to have_no_loading_skeletonexpect(page).to have_css("[data-id='#{unloaded_message.id}']")+ expect(page).to have_css(".-last-read[data-id='#{unloaded_message.id}']")endend