FIX: Add MessageBust.last_id to chat channel subscriptions (#19255)

This commit adds variousMessageBus.last_ids to serializer payloads
for chat channels and the chat view (for chat live pane) so
we can use those IDs when subscribing to MessageBus channels
from chat.

This allows us to ensure that any messages created between the
server being hit and the UI loaded and subscribing end up being
delivered to the client, rather than just silently dropped.

This commit also fixes an issue where we were subscribing to
the new-messages and new-mentions MessageBus channels multiple
times when following/unfollowing a channel multiple times.
This commit is contained in:
Martin Brennan
2022-12-02 10:57:53 +10:00
committed by GitHub
parent a2cec6366f
commit 8437081d94
25 changed files with 448 additions and 96 deletions

View File

@@ -20,6 +20,13 @@ acceptance("Discourse Chat - browse channels", function (needs) {
return helper.response({
public_channels: [],
direct_message_channels: [],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
});
});

View File

@@ -14,8 +14,15 @@ acceptance("Discourse Chat - chat channel info", function (needs) {
const channel = fabricators.chatChannel();
server.get("/chat/chat_channels.json", () => {
return helper.response({
publicMessageChannels: [channel],
directMessageChannels: [],
public_channels: [],
direct_message_channels: [],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
});
});
server.get("/chat/chat_channels/:id.json", () => {

View File

@@ -26,6 +26,13 @@ acceptance(
direct_message_channels: cloneJSON(directMessageChannels).mapBy(
"chat_channel"
),
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
});
});

View File

@@ -79,6 +79,13 @@ acceptance("Discourse Chat - Chat live pane collapse", function (needs) {
helper.response({
public_channels: [],
direct_message_channels: [],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
})
);

View File

@@ -59,6 +59,13 @@ acceptance("Discourse Chat - Chat live pane mobile", function (needs) {
helper.response({
public_channels: [],
direct_message_channels: [],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
})
);

View File

@@ -57,9 +57,20 @@ acceptance("Discourse Chat - Chat live pane", function (needs) {
id: 1,
title: "something",
current_user_membership: { following: true },
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
},
],
direct_message_channels: [],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
})
);

View File

@@ -85,9 +85,20 @@ acceptance(
id: 1,
title: "something",
current_user_membership: { following: true },
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
},
],
direct_message_channels: [],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
})
);
@@ -198,9 +209,17 @@ acceptance(
id: 1,
title: "something",
current_user_membership: { following: true },
message_bus_last_ids: { new_mentions: 0, new_messages: 0 },
},
],
direct_message_channels: [],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
})
);
@@ -246,6 +265,13 @@ acceptance(
helper.response({
public_channels: [],
direct_message_channels: [],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
})
);
@@ -292,6 +318,13 @@ acceptance(
helper.response({
public_channels: [],
direct_message_channels: [],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
})
);

View File

@@ -15,7 +15,7 @@ acceptance("Discourse Chat | User Preferences", function (needs) {
needs.settings({ chat_enabled: true });
needs.pretender(preferencesPretender);
test("when user has not chat sound set", async function (assert) {
test("when user has no chat sound set", async function (assert) {
const sounds = Object.keys(CHAT_SOUNDS);
await visit("/u/eviltrout/preferences/chat");
const dropdown = selectKit("#user_chat_sounds");

View File

@@ -34,12 +34,23 @@ acceptance("Discourse Chat - Sidebar - User Status", function (needs) {
},
chatable_type: "DirectMessage",
title: "@user1",
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
};
server.get("/chat/chat_channels.json", () => {
return helper.response({
public_channels: [],
direct_message_channels: [directMessageChannel],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
});
});
});

View File

@@ -474,6 +474,13 @@ acceptance(
helper.response({
public_channels: [],
direct_message_channels: [],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
})
);
@@ -525,6 +532,13 @@ acceptance(
helper.response({
public_channels: [],
direct_message_channels: [],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
})
);

View File

@@ -54,6 +54,10 @@ acceptance("Discourse Chat - Core Sidebar", function (needs) {
muted: true,
following: true,
},
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
});
directChannels.push({
chatable: {
@@ -82,6 +86,10 @@ acceptance("Discourse Chat - Core Sidebar", function (needs) {
muted: false,
following: true,
},
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
});
server.get("/chat/chat_channels.json", () => {
@@ -97,6 +105,10 @@ acceptance("Discourse Chat - Core Sidebar", function (needs) {
unread_count: 0,
unread_mentions: 0,
},
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
},
{
id: 2,
@@ -108,6 +120,10 @@ acceptance("Discourse Chat - Core Sidebar", function (needs) {
unread_count: 1,
unread_mentions: 0,
},
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
},
{
id: 3,
@@ -121,6 +137,10 @@ acceptance("Discourse Chat - Core Sidebar", function (needs) {
unread_count: 1,
unread_mentions: 1,
},
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
},
{
id: 4,
@@ -132,15 +152,30 @@ acceptance("Discourse Chat - Core Sidebar", function (needs) {
unread_count: 1,
unread_mentions: 1,
},
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
},
],
direct_message_channels: directChannels,
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
});
});
server.get("/chat/1/messages.json", () =>
helper.response({
meta: { can_chat: true, user_silenced: false },
meta: {
can_chat: true,
user_silenced: false,
channel_message_bus_last_id: 0,
},
chat_messages: [],
})
);
@@ -510,6 +545,10 @@ acceptance("Discourse Chat - Plugin Sidebar", function (needs) {
unread_count: 1,
unread_mentions: 1,
},
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
},
{
id: 2,
@@ -521,6 +560,10 @@ acceptance("Discourse Chat - Plugin Sidebar", function (needs) {
unread_count: 1,
unread_mentions: 1,
},
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
},
{
id: 3,
@@ -532,9 +575,20 @@ acceptance("Discourse Chat - Plugin Sidebar", function (needs) {
unread_count: 1,
unread_mentions: 1,
},
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
},
],
direct_message_channels: [],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
});
});
@@ -568,6 +622,13 @@ acceptance(
return helper.response({
public_channels: [],
direct_message_channels: [],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
});
});
});
@@ -604,6 +665,13 @@ acceptance(
return helper.response({
public_channels: [],
direct_message_channels: [],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
});
});
});
@@ -640,6 +708,13 @@ acceptance(
return helper.response({
public_channels: [],
direct_message_channels: [],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
});
});
});
@@ -679,6 +754,13 @@ acceptance(
return helper.response({
public_channels: [],
direct_message_channels: directChannels,
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
});
});
});

View File

@@ -55,6 +55,13 @@ acceptance("Discourse Chat - Create channel modal", function (needs) {
helper.response({
public_channels: [],
direct_message_channels: [],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
})
);

View File

@@ -13,6 +13,13 @@ acceptance("Discourse Chat - delete chat channel modal", function (needs) {
return helper.response({
public_channels: [fabricators.chatChannel({ id: 2 })],
direct_message_channels: [],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
});
});

View File

@@ -32,6 +32,10 @@ export const directMessageChannels = [
following: true,
},
last_message_sent_at: "2021-07-20T08:14:16.950Z",
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
},
},
{
@@ -63,6 +67,10 @@ export const directMessageChannels = [
following: true,
},
last_message_sent_at: "2021-07-05T12:04:00.850Z",
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
},
},
];
@@ -105,6 +113,10 @@ export const chatChannels = {
muted: false,
following: true,
},
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
},
{
id: 7,
@@ -120,6 +132,10 @@ export const chatChannels = {
muted: false,
following: true,
},
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
},
{
id: 4,
@@ -135,6 +151,10 @@ export const chatChannels = {
muted: false,
following: true,
},
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
},
{
id: 5,
@@ -150,6 +170,10 @@ export const chatChannels = {
muted: false,
following: true,
},
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
},
{
id: 6,
@@ -165,6 +189,10 @@ export const chatChannels = {
muted: false,
following: true,
},
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
},
{
id: 10,
@@ -180,6 +208,10 @@ export const chatChannels = {
muted: false,
following: true,
},
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
},
{
id: 11,
@@ -195,9 +227,20 @@ export const chatChannels = {
muted: false,
following: true,
},
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
},
],
direct_message_channels: directMessageChannels.mapBy("chat_channel"),
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
};
const message0 = {

View File

@@ -31,6 +31,10 @@ export default {
name: "My category name",
chatable: categoryChatableFabricator(),
last_message_sent_at: "2021-11-08T21:26:05.710Z",
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
}),
chatChannelMessage: Fabricator(EmberObject, {
@@ -46,5 +50,9 @@ export default {
status: "open",
chatable: directChannelChatableFabricator(),
last_message_sent_at: "2021-11-08T21:26:05.710Z",
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
}),
};

View File

@@ -39,9 +39,20 @@ acceptance("Discourse Chat | Unit | Service | chat", function (needs) {
unread_mentions: 0,
muted: false,
},
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
},
],
direct_message_channels: [],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
});
});