From 36c7eeeea14adae85f812a87ca499d55cd8f58f0 Mon Sep 17 00:00:00 2001 From: Yuriy Kurant Date: Fri, 6 Jun 2025 22:40:38 +0800 Subject: [PATCH 1/2] fix: chat: if empty shows timer placeholder For empty chats, dummy message is still created with id=null (an unsaved Ember model). This change determines by existing id to show timer or placeholder. --- .../components/chat-channel-metadata.gjs | 27 ++++++++++++------- .../components/chat-channel-metadata-test.gjs | 16 +++++++++++ 2 files changed, 33 insertions(+), 10 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 681c472b8c017..fc28d767b52a1 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-metadata.gjs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel-metadata.gjs @@ -1,18 +1,25 @@ import Component from "@glimmer/component"; +import { or } from "truth-helpers"; import { i18n } from "discourse-i18n"; export default class ChatChannelMetadata extends Component { get lastMessageFormattedDate() { - const lastMessageDate = this.showThreadUnreadDate - ? this.args.channel.lastUnreadThreadDate - : this.args.channel.lastMessage.createdAt; + const { createdAt, id } = this.args.channel.lastMessage || {}; - return moment(lastMessageDate).calendar(null, { - sameDay: "LT", - lastDay: `[${i18n("chat.dates.yesterday")}]`, - lastWeek: "dddd", - sameElse: "l", - }); + if (id === null) { + return null; + } else { + const lastMessageDate = this.showThreadUnreadDate + ? this.args.channel.lastUnreadThreadDate + : createdAt; + + return moment(lastMessageDate).calendar(null, { + sameDay: "LT", + lastDay: `[${i18n("chat.dates.yesterday")}]`, + lastWeek: "dddd", + sameElse: "l", + }); + } } get showThreadUnreadDate() { @@ -26,7 +33,7 @@ export default class ChatChannelMetadata extends Component {
{{#if @channel.lastMessage}} {{/if}}
diff --git a/plugins/chat/test/javascripts/components/chat-channel-metadata-test.gjs b/plugins/chat/test/javascripts/components/chat-channel-metadata-test.gjs index 01312aae5cf64..3a0f662662df4 100644 --- a/plugins/chat/test/javascripts/components/chat-channel-metadata-test.gjs +++ b/plugins/chat/test/javascripts/components/chat-channel-metadata-test.gjs @@ -8,6 +8,22 @@ import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators"; module("Discourse Chat | Component | chat-channel-metadata", function (hooks) { setupRenderingTest(hooks); + test("displays created at placeholder for empty chat", async function (assert) { + const self = this; + this.channel = new ChatFabricators(getOwner(this)).directMessageChannel(); + this.channel.lastMessage = new ChatFabricators(getOwner(this)).message({ + channel: this.channel, + created_at: Date.now(), + id: null, + }); + + await render( + + ); + + assert.dom(".chat-channel__metadata-date").hasText("–"); + }); + test("displays last message created at", async function (assert) { const self = this; From 4d4b9ee29b1c27848242c6f6357ececb51a48fc9 Mon Sep 17 00:00:00 2001 From: Yuriy Kurant Date: Fri, 6 Jun 2025 23:39:57 +0800 Subject: [PATCH 2/2] DEV: chat-channel-metadata: code simplified --- .../discourse/components/chat-channel-metadata.gjs | 7 +++---- 1 file changed, 3 insertions(+), 4 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 fc28d767b52a1..c8163135b1f93 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-metadata.gjs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel-metadata.gjs @@ -1,13 +1,12 @@ import Component from "@glimmer/component"; -import { or } from "truth-helpers"; import { i18n } from "discourse-i18n"; export default class ChatChannelMetadata extends Component { get lastMessageFormattedDate() { const { createdAt, id } = this.args.channel.lastMessage || {}; - if (id === null) { - return null; + if (!id) { + return "–"; } else { const lastMessageDate = this.showThreadUnreadDate ? this.args.channel.lastUnreadThreadDate @@ -33,7 +32,7 @@ export default class ChatChannelMetadata extends Component {