Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Change channel priority sorting logic (#44743)

Martin Brennan0033da0c202e
diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-channels-manager.js b/plugins/chat/assets/javascripts/discourse/services/chat-channels-manager.js
index f5beb06993e..adc927c0bb9 100644
--- a/plugins/chat/assets/javascripts/discourse/services/chat-channels-manager.js
+++ b/plugins/chat/assets/javascripts/discourse/services/chat-channels-manager.js
@@ -574,6 +574,8 @@ export default class ChatChannelsManager extends Service {
if (priority) {
return priority;
}
+
+ return this.#compareChannelsAlphabetically(channelA, channelB);
}
return (
diff --git a/plugins/chat/assets/stylesheets/common/chat-channel-list-options.scss b/plugins/chat/assets/stylesheets/common/chat-channel-list-options.scss
index 61052d3fba6..4a4a7f26b44 100644
--- a/plugins/chat/assets/stylesheets/common/chat-channel-list-options.scss
+++ b/plugins/chat/assets/stylesheets/common/chat-channel-list-options.scss
@@ -20,6 +20,13 @@
min-width: 17rem;
}
+.chat-channel-list-sort-menu {
+ &__priority {
+ white-space: normal;
+ text-align: left;
+ }
+}
+
.chat-channel-list-filter-menu .dropdown-menu__item,
.chat-channel-list-sort-menu .dropdown-menu__item,
.chat-channel-list-sort-choice {
diff --git a/plugins/chat/config/locales/client.en.yml b/plugins/chat/config/locales/client.en.yml
index 260292cfdee..5002b360113 100644
--- a/plugins/chat/config/locales/client.en.yml
+++ b/plugins/chat/config/locales/client.en.yml
@@ -671,7 +671,7 @@ en:
alphabetical: "Alphabetically"
recent_activity: "Recent activity"
priority: "Priority"
- priority_description: "Mentions, then unreads, then recent activity"
+ priority_description: "Mentions, then unreads, then recent activity, each sorted alphabetically"
empty:
filtered: "No channels match this filter."
show_all: "Show all channels"
diff --git a/plugins/chat/spec/system/list_channels/drawer_spec.rb b/plugins/chat/spec/system/list_channels/drawer_spec.rb
index 2ccfe332bd6..9214f248c8e 100644
--- a/plugins/chat/spec/system/list_channels/drawer_spec.rb
+++ b/plugins/chat/spec/system/list_channels/drawer_spec.rb
@@ -68,6 +68,20 @@ RSpec.describe "List channels | Drawer" do
it "sorts by urgent, unread messages or threads first when priority is selected" do
current_user.user_option.update!(chat_channel_list_sort: "priority")
+ Fabricate(
+ :chat_message,
+ chat_channel: channel_1,
+ user: current_user,
+ created_at: 1.day.ago,
+ use_service: true,
+ )
+ Fabricate(
+ :chat_message,
+ chat_channel: channel_2,
+ user: current_user,
+ created_at: 1.hour.ago,
+ use_service: true,
+ )
drawer_page.visit_index
Fabricate(
@@ -221,7 +235,7 @@ RSpec.describe "List channels | Drawer" do
Fabricate(:direct_message_channel, users: [current_user, user_3], threading_enabled: true)
end
- it "sorts them by latest activity" do
+ it "sorts unread direct messages before read ones when priority is selected" do
current_user.user_option.update!(chat_channel_list_sort_dms: "priority")
Fabricate(
@@ -245,7 +259,10 @@ RSpec.describe "List channels | Drawer" do
expect(drawer_page).to have_channel_at_position(dm_channel_2, 1)
expect(drawer_page).to have_urgent_channel(dm_channel_2)
- expect(drawer_page).to have_channel_at_position(dm_channel_4, 2)
+ channel_ids =
+ page.all(".chat-channel-row").map { |channel| channel["data-chat-channel-id"] }
+ expect(channel_ids.index(dm_channel_4.id.to_s)).to be >
+ channel_ids.index(dm_channel_2.id.to_s)
end
context "with unread threads" do
diff --git a/plugins/chat/test/javascripts/unit/services/chat-channels-manager-test.js b/plugins/chat/test/javascripts/unit/services/chat-channels-manager-test.js
index 90246b9c4b6..179dc2e487e 100644
--- a/plugins/chat/test/javascripts/unit/services/chat-channels-manager-test.js
+++ b/plugins/chat/test/javascripts/unit/services/chat-channels-manager-test.js
@@ -589,26 +589,46 @@ module("Unit | Service | chat-channels-manager", function (hooks) {
test("sorts urgent, unread, and read channels by priority", function (assert) {
this.preferences.channelsSort = CHAT_CHANNEL_LIST_SORTS.PRIORITY;
- this.buildChannel({ id: 1, slug: "read", createdAt: "2026-09-03" });
+ this.buildChannel({ id: 1, slug: "read-zulu", createdAt: "2026-09-03" });
+ this.buildChannel({ id: 4, slug: "read-alpha", createdAt: "2026-09-01" });
this.buildChannel({
id: 2,
- slug: "unread",
+ slug: "unread-zulu",
createdAt: "2026-09-01",
unreadCount: 1,
});
+ this.buildChannel({
+ id: 5,
+ slug: "unread-alpha",
+ createdAt: "2026-09-03",
+ unreadCount: 1,
+ });
this.buildChannel({
id: 3,
- slug: "urgent",
+ slug: "urgent-zulu",
createdAt: "2026-08-30",
mentionCount: 1,
});
+ this.buildChannel({
+ id: 6,
+ slug: "urgent-alpha",
+ createdAt: "2026-09-04",
+ mentionCount: 1,
+ });
assert.deepEqual(
this.subject.sidebarPublicMessageChannels.map(
(channel) => channel.slug
),
- ["urgent", "unread", "read"],
- "priority groups are ordered"
+ [
+ "urgent-alpha",
+ "urgent-zulu",
+ "unread-alpha",
+ "unread-zulu",
+ "read-alpha",
+ "read-zulu",
+ ],
+ "priority groups are ordered alphabetically"
);
});
@@ -938,26 +958,46 @@ module("Unit | Service | chat-channels-manager", function (hooks) {
test("sorts urgent, unread, and read channels by priority", function (assert) {
this.preferences.channelsSort = CHAT_CHANNEL_LIST_SORTS.PRIORITY;
- this.buildChannel({ id: 1, slug: "read", createdAt: "2026-09-03" });
+ this.buildChannel({ id: 1, slug: "read-zulu", createdAt: "2026-09-03" });
+ this.buildChannel({ id: 4, slug: "read-alpha", createdAt: "2026-09-01" });
this.buildChannel({
id: 2,
- slug: "unread",
+ slug: "unread-zulu",
createdAt: "2026-09-01",
unreadCount: 1,
});
+ this.buildChannel({
+ id: 5,
+ slug: "unread-alpha",
+ createdAt: "2026-09-03",
+ unreadCount: 1,
+ });
this.buildChannel({
id: 3,
- slug: "urgent",
+ slug: "urgent-zulu",
createdAt: "2026-08-30",
mentionCount: 1,
});
+ this.buildChannel({
+ id: 6,
+ slug: "urgent-alpha",
+ createdAt: "2026-09-04",
+ mentionCount: 1,
+ });
assert.deepEqual(
this.subject.publicMessageChannelsByPreference.map(
(channel) => channel.slug
),
- ["urgent", "unread", "read"],
- "priority places urgent, then unread, then read channels"
+ [
+ "urgent-alpha",
+ "urgent-zulu",
+ "unread-alpha",
+ "unread-zulu",
+ "read-alpha",
+ "read-zulu",
+ ],
+ "priority places each group in alphabetical order"
);
});
@@ -1467,8 +1507,8 @@ module("Unit | Service | chat-channels-manager", function (hooks) {
assert.deepEqual(
this.subject.starredChannelsByPreference.map((c) => c.slug),
- ["zulu", "alpha"],
- "starred honors its own priority sort"
+ ["alpha", "zulu"],
+ "starred honors its own priority sort alphabetically"
);
assert.deepEqual(
this.subject.publicMessageChannelsByPreference.map((c) => c.slug),