From b3c94839edbc675dd5d72b7476783d5a0c47ee5f Mon Sep 17 00:00:00 2001 From: David Battersby Date: Thu, 5 Dec 2024 13:33:55 +0400 Subject: [PATCH] FIX: improve chat channel sorting for DMs (#30124) This change sorts unread channels in descending order based on last message date, so channels with the latest activity will always appear at the top. It also adds some improvements for sorting channels with unread threads, now when multiple channels have unread threads, they will be sorted by last thread reply date to ensure more active channels rise to the top. For DM channels, the order is now: - Urgent (green badge) - unread messages, mentions and unread watched threads (most recent activity at top) - Unread (blue badge) - unread tracked threads (most recent thread reply at top) - Everything else (most recent message at top) --- .../components/chat-channel-metadata.gjs | 13 ++- .../discourse/models/chat-channel.js | 10 ++ .../services/chat-channels-manager.js | 31 ++++-- .../spec/system/list_channels/drawer_spec.rb | 96 ++++++++++++------- 4 files changed, 106 insertions(+), 44 deletions(-) diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel-metadata.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-channel-metadata.gjs index e628c932e87..681c472b8c0 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-metadata.gjs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel-metadata.gjs @@ -3,7 +3,11 @@ import { i18n } from "discourse-i18n"; export default class ChatChannelMetadata extends Component { get lastMessageFormattedDate() { - return moment(this.args.channel.lastMessage.createdAt).calendar(null, { + const lastMessageDate = this.showThreadUnreadDate + ? this.args.channel.lastUnreadThreadDate + : this.args.channel.lastMessage.createdAt; + + return moment(lastMessageDate).calendar(null, { sameDay: "LT", lastDay: `[${i18n("chat.dates.yesterday")}]`, lastWeek: "dddd", @@ -11,6 +15,13 @@ export default class ChatChannelMetadata extends Component { }); } + get showThreadUnreadDate() { + return ( + this.args.channel.lastUnreadThreadDate > + this.args.channel.lastMessage.createdAt + ); + } +