mirror of
https://github.com/discourse/discourse.git
synced 2025-06-02 16:29:32 +08:00
FIX: sort chat channels by mentions, unread and channel title (#25565)
This change will sort channels by activity on mobile, with preference to those with urgent or unread messages. Channels with mentions will appear first, followed by channels with unread messages, then finally everything else sorted by the channel title (alphabetically).
This commit is contained in:
@ -50,24 +50,55 @@ RSpec.describe "List channels | mobile", type: :system, mobile: true do
|
||||
end
|
||||
|
||||
context "when multiple category channels are present" do
|
||||
fab!(:channel_1) { Fabricate(:category_channel, name: "b channel") }
|
||||
fab!(:channel_2) { Fabricate(:category_channel, name: "a channel") }
|
||||
fab!(:channel_1) { Fabricate(:category_channel, name: "a channel") }
|
||||
fab!(:channel_2) { Fabricate(:category_channel, name: "b channel") }
|
||||
fab!(:channel_3) { Fabricate(:category_channel, name: "c channel") }
|
||||
fab!(:channel_4) { Fabricate(:category_channel, name: "d channel") }
|
||||
|
||||
before do
|
||||
channel_1.add(current_user)
|
||||
channel_2.add(current_user)
|
||||
channel_3.add(current_user)
|
||||
channel_4.add(current_user)
|
||||
end
|
||||
|
||||
it "sorts them alphabetically" do
|
||||
visit("/chat")
|
||||
page.find("#c-footer-channels").click
|
||||
it "sorts them by mentions, unread, then alphabetical order" do
|
||||
Jobs.run_immediately!
|
||||
|
||||
expect(page.find("#public-channels a:nth-child(1)")["data-chat-channel-id"]).to eq(
|
||||
channel_2.id.to_s,
|
||||
Fabricate(
|
||||
:chat_message,
|
||||
chat_channel: channel_1,
|
||||
created_at: 10.minutes.ago,
|
||||
use_service: true,
|
||||
)
|
||||
Fabricate(
|
||||
:chat_message,
|
||||
chat_channel: channel_2,
|
||||
created_at: 5.minutes.ago,
|
||||
use_service: true,
|
||||
)
|
||||
Fabricate(
|
||||
:chat_message_with_service,
|
||||
chat_channel: channel_4,
|
||||
message: "Hey @#{current_user.username}",
|
||||
user: Fabricate(:user),
|
||||
)
|
||||
|
||||
Fabricate(:chat_message, chat_channel: channel_3, user: current_user, use_service: true)
|
||||
|
||||
visit("/chat/channels")
|
||||
|
||||
# channel with mentions should be first
|
||||
expect(page.find("#public-channels a:nth-child(1)")["data-chat-channel-id"]).to eq(
|
||||
channel_4.id.to_s,
|
||||
)
|
||||
# channels with unread messages are next, sorted by title
|
||||
expect(page.find("#public-channels a:nth-child(2)")["data-chat-channel-id"]).to eq(
|
||||
channel_1.id.to_s,
|
||||
)
|
||||
expect(page.find("#public-channels a:nth-child(3)")["data-chat-channel-id"]).to eq(
|
||||
channel_2.id.to_s,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user