mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 15:24:05 +08:00
FIX: ensures chat channel metadata date is updated (#19314)
This commit is contained in:
parent
3c6bd97efe
commit
105f38c04a
|
@ -1,16 +1,18 @@
|
||||||
import Component from "@glimmer/component";
|
import Component from "@glimmer/component";
|
||||||
|
|
||||||
export default class ChatChannelMetadata extends Component {
|
export default class ChatChannelMetadata extends Component {
|
||||||
unreadIndicator = false;
|
unreadIndicator = false;
|
||||||
|
|
||||||
get lastMessageFormatedDate() {
|
get lastMessageFormatedDate() {
|
||||||
return moment(this.args.channel.last_message_sent_at).calendar(null, {
|
return moment(this.args.channel.get("last_message_sent_at")).calendar(
|
||||||
|
null,
|
||||||
|
{
|
||||||
sameDay: "LT",
|
sameDay: "LT",
|
||||||
nextDay: "[Tomorrow]",
|
nextDay: "[Tomorrow]",
|
||||||
nextWeek: "dddd",
|
nextWeek: "dddd",
|
||||||
lastDay: "[Yesterday]",
|
lastDay: "[Yesterday]",
|
||||||
lastWeek: "dddd",
|
lastWeek: "dddd",
|
||||||
sameElse: "l",
|
sameElse: "l",
|
||||||
});
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -748,16 +748,11 @@ export default class Chat extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.userChatChannelTrackingStateChanged();
|
this.userChatChannelTrackingStateChanged();
|
||||||
|
channel.set("last_message_sent_at", new Date());
|
||||||
|
|
||||||
// Update last_message_sent_at timestamp for channel if direct message
|
(this.directMessageChannels || [])
|
||||||
const dmChatChannel = (this.directMessageChannels || []).findBy(
|
.findBy("id", parseInt(channel.id, 10))
|
||||||
"id",
|
?.reSortDirectMessageChannels?.();
|
||||||
parseInt(channel.id, 10)
|
|
||||||
);
|
|
||||||
if (dmChatChannel) {
|
|
||||||
dmChatChannel.set("last_message_sent_at", new Date());
|
|
||||||
this.reSortDirectMessageChannels();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
channel.message_bus_last_ids.new_messages
|
channel.message_bus_last_ids.new_messages
|
||||||
);
|
);
|
||||||
|
|
|
@ -9,12 +9,18 @@ module("Discourse Chat | Component | chat-channel-metadata", function (hooks) {
|
||||||
setupRenderingTest(hooks);
|
setupRenderingTest(hooks);
|
||||||
|
|
||||||
test("displays last message sent at", async function (assert) {
|
test("displays last message sent at", async function (assert) {
|
||||||
const lastMessageSentAt = moment();
|
let lastMessageSentAt = moment().subtract(1, "day");
|
||||||
this.channel = fabricators.directMessageChatChannel({
|
this.channel = fabricators.directMessageChatChannel({
|
||||||
last_message_sent_at: lastMessageSentAt,
|
last_message_sent_at: lastMessageSentAt,
|
||||||
});
|
});
|
||||||
await render(hbs`<ChatChannelMetadata @channel={{this.channel}} />`);
|
await render(hbs`<ChatChannelMetadata @channel={{this.channel}} />`);
|
||||||
|
|
||||||
|
assert.dom(".chat-channel-metadata__date").hasText("Yesterday");
|
||||||
|
|
||||||
|
lastMessageSentAt = moment();
|
||||||
|
this.channel.set("last_message_sent_at", lastMessageSentAt);
|
||||||
|
await render(hbs`<ChatChannelMetadata @channel={{this.channel}} />`);
|
||||||
|
|
||||||
assert
|
assert
|
||||||
.dom(".chat-channel-metadata__date")
|
.dom(".chat-channel-metadata__date")
|
||||||
.hasText(lastMessageSentAt.format("LT"));
|
.hasText(lastMessageSentAt.format("LT"));
|
||||||
|
|
|
@ -134,6 +134,28 @@ acceptance("Discourse Chat | Unit | Service | chat", function (needs) {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("new message", async function (assert) {
|
||||||
|
setupMockPresenceChannel(this.chatService);
|
||||||
|
await this.chatService.forceRefreshChannels();
|
||||||
|
|
||||||
|
await publishToMessageBus("/chat/1/new-messages", {
|
||||||
|
user_id: this.currentUser.id,
|
||||||
|
username: this.currentUser.username,
|
||||||
|
message_id: 124,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
this.currentUser.chat_channel_tracking_state[1].chat_message_id,
|
||||||
|
124,
|
||||||
|
"updates tracking state last message id to the message id sent by current user"
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
this.currentUser.chat_channel_tracking_state[1].unread_count,
|
||||||
|
2,
|
||||||
|
"does not increment unread count"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("/chat/:channelId/new-messages - message from current user", async function (assert) {
|
test("/chat/:channelId/new-messages - message from current user", async function (assert) {
|
||||||
setupMockPresenceChannel(this.chatService);
|
setupMockPresenceChannel(this.chatService);
|
||||||
await this.chatService.forceRefreshChannels();
|
await this.chatService.forceRefreshChannels();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user