Skip to content

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

FEATURE: Change channel priority sorting logic for non-DM channels (#44877)

Martin Brennan11b28ab588ca
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel-list-sort-choice.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-channel-list-sort-choice.gjs
index 2e4e8978179..0673a0c995d 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-list-sort-choice.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel-list-sort-choice.gjs
@@ -35,6 +35,17 @@ export const SORT_OPTIONS = [
export default class ChatChannelListSortChoice extends Component {
@service chatChannelListPreferences;
+ get descriptionKey() {
+ if (
+ this.args.section === "dms" &&
+ this.args.choice.value === CHAT_CHANNEL_LIST_SORTS.PRIORITY
+ ) {
+ return "chat.channel_list.sort.priority_description_dms";
+ }
+
+ return this.args.choice.descriptionKey;
+ }
+
get isCurrentSort() {
return (
this.chatChannelListPreferences.sortFor(this.args.section) ===
@@ -73,9 +84,9 @@ export default class ChatChannelListSortChoice extends Component {
<span class="chat-channel-list-sort-menu__label-title">
{{i18n @choice.labelKey}}
</span>
- {{#if @choice.descriptionKey}}
+ {{#if this.descriptionKey}}
<span class="chat-channel-list-sort-menu__label-description">
- {{i18n @choice.descriptionKey}}
+ {{i18n this.descriptionKey}}
</span>
{{/if}}
</span>
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..40ae5c60133 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,10 @@ export default class ChatChannelsManager extends Service {
if (priority) {
return priority;
}
+
+ if (section !== "dms") {
+ 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..5f06fca930a 100644
--- a/plugins/chat/config/locales/client.en.yml
+++ b/plugins/chat/config/locales/client.en.yml
@@ -671,7 +671,8 @@ 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"
+ priority_description_dms: "Mentions, then unreads, then recent activity"
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..80ec73835ed 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(
diff --git a/plugins/chat/test/javascripts/components/chat-channel-list-sidebar-menu-test.gjs b/plugins/chat/test/javascripts/components/chat-channel-list-sidebar-menu-test.gjs
index b3883f11fda..abedd0d66eb 100644
--- a/plugins/chat/test/javascripts/components/chat-channel-list-sidebar-menu-test.gjs
+++ b/plugins/chat/test/javascripts/components/chat-channel-list-sidebar-menu-test.gjs
@@ -675,6 +675,27 @@ module("Integration | Component | ChatChannelListSortMenu", function (hooks) {
"the selected sort is saved"
);
});
+
+ test("describes priority sorting by recency for direct messages", async function (assert) {
+ await render(
+ <template><ChatChannelListSortMenu @section="dms" /></template>
+ );
+
+ assert
+ .dom(".chat-channel-list-sort-menu__priority")
+ .includesText(
+ i18n("chat.channel_list.sort.priority"),
+ "the priority option retains its title"
+ )
+ .includesText(
+ i18n("chat.channel_list.sort.priority_description_dms"),
+ "the priority option describes recency ordering"
+ )
+ .doesNotIncludeText(
+ i18n("chat.channel_list.sort.priority_description"),
+ "the channel-specific alphabetical description is hidden"
+ );
+ });
});
module(
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..6ea9cb34f47 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"
);
});
@@ -772,6 +792,59 @@ module("Unit | Service | chat-channels-manager", function (hooks) {
);
});
+ test("sorts priority groups by recent activity", function (assert) {
+ this.preferences.dmsSort = CHAT_CHANNEL_LIST_SORTS.PRIORITY;
+ this.buildDirectMessageChannel({
+ id: 1,
+ title: "Read newer",
+ createdAt: "2026-09-04",
+ });
+ this.buildDirectMessageChannel({
+ id: 2,
+ title: "Read older",
+ createdAt: "2026-09-01",
+ });
+ this.buildDirectMessageChannel({
+ id: 3,
+ title: "Unread older",
+ createdAt: "2026-09-02",
+ unreadCount: 1,
+ });
+ this.buildDirectMessageChannel({
+ id: 4,
+ title: "Unread newer",
+ createdAt: "2026-09-03",
+ unreadCount: 1,
+ });
+ this.buildDirectMessageChannel({
+ id: 5,
+ title: "Mention older",
+ createdAt: "2026-08-30",
+ mentionCount: 1,
+ });
+ this.buildDirectMessageChannel({
+ id: 6,
+ title: "Mention newer",
+ createdAt: "2026-09-05",
+ mentionCount: 1,
+ });
+
+ assert.deepEqual(
+ this.subject.sidebarDirectMessageChannels.map(
+ (channel) => channel.title
+ ),
+ [
+ "Mention newer",
+ "Mention older",
+ "Unread newer",
+ "Unread older",
+ "Read newer",
+ "Read older",
+ ],
+ "priority groups retain recency ordering for direct messages"
+ );
+ });
+
test("keeps an active direct message within the sidebar limit", function (assert) {
for (let index = 0; index < 50; index++) {
this.buildDirectMessageChannel({
@@ -938,26 +1011,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 +1560,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),