mirror of
https://github.com/discourse/discourse.git
synced 2024-12-20 11:38:44 +08:00
FIX: chat channel sort order consistency in sidebar (#30180)
This change creates a shallow copy of the public message channels so we don't change the original array while sorting. Without this change the publicMessageChannels getter cache gets invalidated and cached again with the sorted channels array instead, which causes a bug where the sidebar channel list sorting order is updated by activity when user interacts with the chat drawer.
This commit is contained in:
parent
acc180611f
commit
f0ea57e30e
|
@ -34,9 +34,7 @@ export default class ChannelsListPublic extends Component {
|
|||
}
|
||||
|
||||
get channelList() {
|
||||
return this.args.sortByActivity === true
|
||||
? this.chatChannelsManager.publicMessageChannelsByActivity
|
||||
: this.chatChannelsManager.publicMessageChannels;
|
||||
return this.chatChannelsManager.publicMessageChannelsByActivity;
|
||||
}
|
||||
|
||||
@action
|
||||
|
|
|
@ -22,7 +22,7 @@ export default class ChatDrawerRoutesChannels extends Component {
|
|||
|
||||
{{#if this.chatStateManager.isDrawerExpanded}}
|
||||
<div class="chat-drawer-content">
|
||||
<ChannelsListPublic @sortByActivity={{true}} />
|
||||
<ChannelsListPublic />
|
||||
</div>
|
||||
|
||||
<ChatFooter />
|
||||
|
|
|
@ -17,7 +17,7 @@ export default class ChatRoutesChannels extends Component {
|
|||
</navbar.Actions>
|
||||
</Navbar>
|
||||
|
||||
<ChannelsListPublic @sortByActivity={{true}} />
|
||||
<ChannelsListPublic />
|
||||
</div>
|
||||
</template>
|
||||
}
|
||||
|
|
|
@ -136,7 +136,7 @@ export default class ChatChannelsManager extends Service {
|
|||
}
|
||||
|
||||
get publicMessageChannelsByActivity() {
|
||||
return this.#sortChannelsByActivity(this.publicMessageChannels);
|
||||
return this.#sortChannelsByActivity([...this.publicMessageChannels]);
|
||||
}
|
||||
|
||||
@cached
|
||||
|
|
|
@ -4,6 +4,7 @@ RSpec.describe "List channels | sidebar", type: :system do
|
|||
fab!(:current_user) { Fabricate(:user) }
|
||||
|
||||
let(:chat) { PageObjects::Pages::Chat.new }
|
||||
let(:drawer_page) { PageObjects::Pages::ChatDrawer.new }
|
||||
|
||||
before do
|
||||
chat_system_bootstrap
|
||||
|
@ -72,6 +73,24 @@ RSpec.describe "List channels | sidebar", type: :system do
|
|||
".channel-#{channel_1.id}",
|
||||
)
|
||||
end
|
||||
|
||||
it "does not change sorting order when using drawer" do
|
||||
Fabricate(:chat_message, chat_channel: channel_1)
|
||||
visit("/")
|
||||
|
||||
expect(page.find("#sidebar-section-content-chat-channels li:nth-child(1)")).to have_css(
|
||||
".channel-#{channel_2.id}",
|
||||
)
|
||||
|
||||
drawer_page.visit_index
|
||||
drawer_page.click_channels
|
||||
|
||||
expect(drawer_page).to have_channel_at_position(channel_1, 1)
|
||||
|
||||
expect(page.find("#sidebar-section-content-chat-channels li:nth-child(1)")).to have_css(
|
||||
".channel-#{channel_2.id}",
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "when direct message channels" do
|
||||
|
|
Loading…
Reference in New Issue
Block a user