FIX: correctly save scroll position in channel (#25345)

Due to an incorrect test the previous service was incorrectly implementing the map, and was most importantly not deleting the state when reaching bottom.
This commit is contained in:
Joffrey JAFFEUX 2024-01-19 22:49:14 +01:00 committed by GitHub
parent ccb5fa1a5a
commit aee7197c43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 7 deletions

View File

@ -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,

View File

@ -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);
}
}
}

View File

@ -375,7 +375,13 @@ RSpec.describe "Chat channel", type: :system do
sidebar_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)
end
end
end