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..c8163135b1f93 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-metadata.gjs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel-metadata.gjs @@ -3,16 +3,22 @@ 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) { + return "–"; + } 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() { 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;