A platform for community discussion. Free, open, simple.
FIX: correctly save scroll position in channel (#25345)
Joffrey JAFFEUXaee7197c435c
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjsindex 87eddf7955f..f93fe4c88e0 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs@@ -497,7 +497,7 @@ export default class ChatChannel extends Component {if (state.atBottom) {this.fetchMoreMessages({ direction: FUTURE });- this.chatChannelScrollPositions.remove(this.args.channel.id);+ this.chatChannelScrollPositions.delete(this.args.channel.id);} else {this.chatChannelScrollPositions.set(this.args.channel.id,diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-channel-scroll-positions.js b/plugins/chat/assets/javascripts/discourse/services/chat-channel-scroll-positions.jsindex 9a4888c7608..70602e94fa5 100644--- a/plugins/chat/assets/javascripts/discourse/services/chat-channel-scroll-positions.js+++ b/plugins/chat/assets/javascripts/discourse/services/chat-channel-scroll-positions.js@@ -5,13 +5,17 @@ import { TrackedMap } from "@ember-compat/tracked-built-ins";export default class ChatChannelScrollPositions extends Service {@tracked positions = new TrackedMap();- add(channelId, position) {- this.positions.set(channelId, position);+ get(id) {+ return this.positions.get(id);}- remove(channelId) {- if (this.positions.has(channelId)) {- this.positions.delete(channelId);+ set(id, position) {+ this.positions.set(id, position);+ }++ delete(id) {+ if (this.positions.has(id)) {+ this.positions.delete(id);}}}diff --git a/plugins/chat/spec/system/chat_channel_spec.rb b/plugins/chat/spec/system/chat_channel_spec.rbindex 1acbb05eb9b..37b7d66406e 100644--- a/plugins/chat/spec/system/chat_channel_spec.rb+++ b/plugins/chat/spec/system/chat_channel_spec.rb@@ -375,7 +375,13 @@ RSpec.describe "Chat channel", type: :system dosidebar_page.open_channel(channel_2)sidebar_page.open_channel(channel_1)- expect(channel_page.messages).to have_message(id: channel_1.chat_messages[2].id)+ expect(channel_page.messages).to have_no_message(id: channel_1.chat_messages[49].id)++ find(".chat-scroll-to-bottom__button.visible").click+ sidebar_page.open_channel(channel_2)+ sidebar_page.open_channel(channel_1)++ expect(channel_page.messages).to have_message(id: channel_1.chat_messages[49].id)endendend