From 8437081d94de6c3280871949f980f0033587cff0 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Fri, 2 Dec 2022 10:57:53 +1000 Subject: [PATCH] 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. --- .../serializers/chat_channel_serializer.rb | 10 +- .../app/serializers/chat_view_serializer.rb | 1 + .../structured_channel_serializer.rb | 17 +- .../discourse/components/chat-live-pane.js | 20 +- .../discourse/initializers/chat-setup.js | 2 +- .../javascripts/discourse/services/chat.js | 182 +++++++++++------- .../requests/chat_channel_controller_spec.rb | 15 ++ .../spec/requests/chat_controller_spec.rb | 8 +- .../spec/system/hashtag_autocomplete_spec.rb | 19 +- .../acceptance/chat-browse-test.js | 7 + .../acceptance/chat-channel-info-test.js | 11 +- .../acceptance/chat-channels-list-test.js | 7 + .../chat-live-pane-collapse-test.js | 7 + .../acceptance/chat-live-pane-mobile-test.js | 7 + .../chat-live-pane-silenced-user-test.js | 11 ++ .../acceptance/chat-live-pane-test.js | 33 ++++ .../acceptance/chat-preferences-test.js | 2 +- .../chat-sidebar-user-status-test.js | 11 ++ .../acceptance/chat-transcript-test.js | 14 ++ .../acceptance/core-sidebar-test.js | 84 +++++++- .../acceptance/create-channel-test.js | 7 + .../delete-chat-channel-modal-test.js | 7 + .../chat/test/javascripts/chat-fixtures.js | 43 +++++ .../test/javascripts/helpers/fabricators.js | 8 + .../javascripts/unit/services/chat-test.js | 11 ++ 25 files changed, 448 insertions(+), 96 deletions(-) diff --git a/plugins/chat/app/serializers/chat_channel_serializer.rb b/plugins/chat/app/serializers/chat_channel_serializer.rb index 6a194047f9..d3fedfa9c4 100644 --- a/plugins/chat/app/serializers/chat_channel_serializer.rb +++ b/plugins/chat/app/serializers/chat_channel_serializer.rb @@ -18,7 +18,8 @@ class ChatChannelSerializer < ApplicationSerializer :total_messages, :archive_topic_id, :memberships_count, - :current_user_membership + :current_user_membership, + :message_bus_last_ids def initialize(object, opts) super(object, opts) @@ -94,6 +95,13 @@ class ChatChannelSerializer < ApplicationSerializer ).as_json end + def message_bus_last_ids + { + new_messages: MessageBus.last_id("/chat/#{object.id}/new-messages"), + new_mentions: MessageBus.last_id("/chat/#{object.id}/new-mentions"), + } + end + alias_method :include_archive_topic_id?, :include_archive_status? alias_method :include_total_messages?, :include_archive_status? alias_method :include_archived_messages?, :include_archive_status? diff --git a/plugins/chat/app/serializers/chat_view_serializer.rb b/plugins/chat/app/serializers/chat_view_serializer.rb index 54b78b8401..566474ec40 100644 --- a/plugins/chat/app/serializers/chat_view_serializer.rb +++ b/plugins/chat/app/serializers/chat_view_serializer.rb @@ -22,6 +22,7 @@ class ChatViewSerializer < ApplicationSerializer can_moderate: scope.can_moderate_chat?(object.chat_channel.chatable), can_delete_self: scope.can_delete_own_chats?(object.chat_channel.chatable), can_delete_others: scope.can_delete_other_chats?(object.chat_channel.chatable), + channel_message_bus_last_id: MessageBus.last_id("/chat/#{object.chat_channel.id}"), } meta_hash[:can_load_more_past] = object.can_load_more_past unless object.can_load_more_past.nil? meta_hash[ diff --git a/plugins/chat/app/serializers/structured_channel_serializer.rb b/plugins/chat/app/serializers/structured_channel_serializer.rb index e3ee4f7783..5da682e3ec 100644 --- a/plugins/chat/app/serializers/structured_channel_serializer.rb +++ b/plugins/chat/app/serializers/structured_channel_serializer.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StructuredChannelSerializer < ApplicationSerializer - attributes :public_channels, :direct_message_channels + attributes :public_channels, :direct_message_channels, :message_bus_last_ids def public_channels object[:public_channels].map do |channel| @@ -29,4 +29,19 @@ class StructuredChannelSerializer < ApplicationSerializer return if scope.anonymous? object[:memberships].find { |membership| membership.chat_channel_id == channel_id } end + + def message_bus_last_ids + last_ids = { + channel_metadata: MessageBus.last_id("/chat/channel-metadata"), + channel_edits: MessageBus.last_id("/chat/channel-edits"), + channel_status: MessageBus.last_id("/chat/channel-status"), + new_channel: MessageBus.last_id("/chat/new-channel"), + } + if !scope.anonymous? + last_ids[:user_tracking_state] = MessageBus.last_id( + "/chat/user-tracking-state/#{scope.user.id}", + ) + end + last_ids + end end diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-live-pane.js b/plugins/chat/assets/javascripts/discourse/components/chat-live-pane.js index 887579d9e2..db465aa10c 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-live-pane.js +++ b/plugins/chat/assets/javascripts/discourse/components/chat-live-pane.js @@ -403,6 +403,8 @@ export default Component.extend({ can_flag: messages.resultSetMeta.can_flag, user_silenced: messages.resultSetMeta.user_silenced, can_moderate: messages.resultSetMeta.can_moderate, + channel_message_bus_last_id: + messages.resultSetMeta.channel_message_bus_last_id, }, registeredChatChannelId: this.chatChannel.id, }); @@ -1407,13 +1409,17 @@ export default Component.extend({ _subscribeToUpdates(channelId) { this._unsubscribeToUpdates(channelId); - this.messageBus.subscribe(`/chat/${channelId}`, (busData) => { - if (!this.details.can_load_more_future || busData.type !== "sent") { - this.handleMessage(busData); - } else { - this.set("hasNewMessages", true); - } - }); + this.messageBus.subscribe( + `/chat/${channelId}`, + (busData) => { + if (!this.details.can_load_more_future || busData.type !== "sent") { + this.handleMessage(busData); + } else { + this.set("hasNewMessages", true); + } + }, + this.details.channel_message_bus_last_id + ); }, @bind diff --git a/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js b/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js index f295772574..e00ee2b59b 100644 --- a/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js +++ b/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js @@ -101,7 +101,7 @@ export default { if (currentUser?.chat_channels) { this.chatService.setupWithPreloadedChannels(currentUser.chat_channels); } else { - this.chatService.getChannels(); + this.chatService.setupWithoutPreloadedChannels(); } const chatNotificationManager = container.lookup( diff --git a/plugins/chat/assets/javascripts/discourse/services/chat.js b/plugins/chat/assets/javascripts/discourse/services/chat.js index e92205eb6e..aa866f4e15 100644 --- a/plugins/chat/assets/javascripts/discourse/services/chat.js +++ b/plugins/chat/assets/javascripts/discourse/services/chat.js @@ -79,11 +79,6 @@ export default class Chat extends Service { if (this.userCanChat) { this.set("allChannels", []); - this._subscribeToNewChannelUpdates(); - this._subscribeToUserTrackingChannel(); - this._subscribeToChannelEdits(); - this._subscribeToChannelMetadata(); - this._subscribeToChannelStatusChange(); this.presenceChannel = this.presence.getChannel("/chat/online"); this.draftStore = {}; @@ -118,10 +113,25 @@ export default class Chat extends Service { setupWithPreloadedChannels(channels) { this.currentUser.set("chat_channel_tracking_state", {}); this._processChannels(channels || {}); + this.subscribeToChannelMessageBus(); this.userChatChannelTrackingStateChanged(); this.appEvents.trigger("chat:refresh-channels"); } + setupWithoutPreloadedChannels() { + this.getChannels().then(() => { + this.subscribeToChannelMessageBus(); + }); + } + + subscribeToChannelMessageBus() { + this._subscribeToNewChannelUpdates(); + this._subscribeToUserTrackingChannel(); + this._subscribeToChannelEdits(); + this._subscribeToChannelMetadata(); + this._subscribeToChannelStatusChange(); + } + willDestroy() { super.willDestroy(...arguments); @@ -342,6 +352,8 @@ export default class Chat extends Service { } _processChannels(channels) { + // Must be set first because `processChannels` relies on this data. + this.set("messageBusLastIds", channels.message_bus_last_ids); this.setProperties({ publicChannels: A( this.sortPublicChannels( @@ -593,29 +605,37 @@ export default class Chat extends Service { } _subscribeToChannelMetadata() { - this.messageBus.subscribe("/chat/channel-metadata", (busData) => { - this.getChannelBy("id", busData.chat_channel_id).then((channel) => { - if (channel) { - channel.setProperties({ - memberships_count: busData.memberships_count, - }); - this.appEvents.trigger("chat:refresh-channel-members"); - } - }); - }); + this.messageBus.subscribe( + "/chat/channel-metadata", + (busData) => { + this.getChannelBy("id", busData.chat_channel_id).then((channel) => { + if (channel) { + channel.setProperties({ + memberships_count: busData.memberships_count, + }); + this.appEvents.trigger("chat:refresh-channel-members"); + } + }); + }, + this.messageBusLastIds.channel_metadata + ); } _subscribeToChannelEdits() { - this.messageBus.subscribe("/chat/channel-edits", (busData) => { - this.getChannelBy("id", busData.chat_channel_id).then((channel) => { - if (channel) { - channel.setProperties({ - title: busData.name, - description: busData.description, - }); - } - }); - }); + this.messageBus.subscribe( + "/chat/channel-edits", + (busData) => { + this.getChannelBy("id", busData.chat_channel_id).then((channel) => { + if (channel) { + channel.setProperties({ + title: busData.name, + description: busData.description, + }); + } + }); + }, + this.messageBusLastIds.channel_edits + ); } _subscribeToChannelStatusChange() { @@ -641,7 +661,7 @@ export default class Chat extends Service { } this.appEvents.trigger("chat:refresh-channel", channel.id); - }); + }, this.messageBusLastIds.channel_status); }); } @@ -658,9 +678,13 @@ export default class Chat extends Service { } _subscribeToNewChannelUpdates() { - this.messageBus.subscribe("/chat/new-channel", (busData) => { - this.startTrackingChannel(ChatChannel.create(busData.chat_channel)); - }); + this.messageBus.subscribe( + "/chat/new-channel", + (busData) => { + this.startTrackingChannel(ChatChannel.create(busData.chat_channel)); + }, + this.messageBusLastIds.new_channel + ); } _unsubscribeFromNewDmChannelUpdates() { @@ -672,54 +696,71 @@ export default class Chat extends Service { return; } + // We do this first so we don't multi-subscribe to mention + messages + // messageBus channels for this chat channel, since _subscribeToSingleUpdateChannel + // is called from multiple places. + this._unsubscribeFromChatChannel(channel); + if (!channel.isDirectMessageChannel) { this._subscribeToMentionChannel(channel); } - this.messageBus.subscribe(`/chat/${channel.id}/new-messages`, (busData) => { - const trackingState = - this.currentUser.chat_channel_tracking_state[channel.id]; - - if (busData.user_id === this.currentUser.id) { - // User sent message, update tracking state to no unread - trackingState.set("chat_message_id", busData.message_id); - } else { - // Ignored user sent message, update tracking state to no unread - if (this.currentUser.ignored_users.includes(busData.username)) { - trackingState.set("chat_message_id", busData.message_id); - } else { - // Message from other user. Increment trackings state - if (busData.message_id > (trackingState.chat_message_id || 0)) { - trackingState.set("unread_count", trackingState.unread_count + 1); - } - } - } - this.userChatChannelTrackingStateChanged(); - - // Update last_message_sent_at timestamp for channel if direct message - const dmChatChannel = (this.directMessageChannels || []).findBy( - "id", - parseInt(channel.id, 10) - ); - if (dmChatChannel) { - dmChatChannel.set("last_message_sent_at", new Date()); - this.reSortDirectMessageChannels(); - } - }); + this._subscribeToNewMessagesChannel(channel); } _subscribeToMentionChannel(channel) { - this.messageBus.subscribe(`/chat/${channel.id}/new-mentions`, () => { - const trackingState = - this.currentUser.chat_channel_tracking_state[channel.id]; - if (trackingState) { - trackingState.set( - "unread_mentions", - (trackingState.unread_mentions || 0) + 1 - ); + this.messageBus.subscribe( + `/chat/${channel.id}/new-mentions`, + () => { + const trackingState = + this.currentUser.chat_channel_tracking_state[channel.id]; + if (trackingState) { + trackingState.set( + "unread_mentions", + (trackingState.unread_mentions || 0) + 1 + ); + this.userChatChannelTrackingStateChanged(); + } + }, + channel.message_bus_last_ids.new_mentions + ); + } + + _subscribeToNewMessagesChannel(channel) { + this.messageBus.subscribe( + `/chat/${channel.id}/new-messages`, + (busData) => { + const trackingState = + this.currentUser.chat_channel_tracking_state[channel.id]; + + if (busData.user_id === this.currentUser.id) { + // User sent message, update tracking state to no unread + trackingState.set("chat_message_id", busData.message_id); + } else { + // Ignored user sent message, update tracking state to no unread + if (this.currentUser.ignored_users.includes(busData.username)) { + trackingState.set("chat_message_id", busData.message_id); + } else { + // Message from other user. Increment trackings state + if (busData.message_id > (trackingState.chat_message_id || 0)) { + trackingState.set("unread_count", trackingState.unread_count + 1); + } + } + } this.userChatChannelTrackingStateChanged(); - } - }); + + // Update last_message_sent_at timestamp for channel if direct message + const dmChatChannel = (this.directMessageChannels || []).findBy( + "id", + parseInt(channel.id, 10) + ); + if (dmChatChannel) { + dmChatChannel.set("last_message_sent_at", new Date()); + this.reSortDirectMessageChannels(); + } + }, + channel.message_bus_last_ids.new_messages + ); } async followChannel(channel) { @@ -779,7 +820,8 @@ export default class Chat extends Service { trackingState.set("unread_mentions", 0); this.userChatChannelTrackingStateChanged(); } - } + }, + this.messageBusLastIds.user_tracking_state ); } diff --git a/plugins/chat/spec/requests/chat_channel_controller_spec.rb b/plugins/chat/spec/requests/chat_channel_controller_spec.rb index 9e88a47f72..7ea20a6ed7 100644 --- a/plugins/chat/spec/requests/chat_channel_controller_spec.rb +++ b/plugins/chat/spec/requests/chat_channel_controller_spec.rb @@ -101,6 +101,21 @@ RSpec.describe Chat::ChatChannelsController do expect(cc["current_user_membership"]["unread_mentions"]).to eq(1) end + it "returns the last message bus ids for various message bus channels scoped to this channel id" do + sign_in(admin) + get "/chat/chat_channels.json" + expect(response.status).to eq(200) + + expect(response.parsed_body["message_bus_last_ids"]["channel_metadata"]).not_to eq(nil) + expect(response.parsed_body["message_bus_last_ids"]["channel_edits"]).not_to eq(nil) + expect(response.parsed_body["message_bus_last_ids"]["channel_status"]).not_to eq(nil) + expect(response.parsed_body["message_bus_last_ids"]["new_channel"]).not_to eq(nil) + + first_channel = response.parsed_body["public_channels"][0] + expect(first_channel["message_bus_last_ids"]["new_messages"]).not_to eq(nil) + expect(first_channel["message_bus_last_ids"]["new_mentions"]).not_to eq(nil) + end + describe "direct messages" do fab!(:user1) { Fabricate(:user) } fab!(:user2) { Fabricate(:user) } diff --git a/plugins/chat/spec/requests/chat_controller_spec.rb b/plugins/chat/spec/requests/chat_controller_spec.rb index ad42097db2..4d81dba48a 100644 --- a/plugins/chat/spec/requests/chat_controller_spec.rb +++ b/plugins/chat/spec/requests/chat_controller_spec.rb @@ -137,6 +137,11 @@ RSpec.describe Chat::ChatController do expect(reactions[smile_emoji]["reacted"]).to be false end + it "sends the last message bus id for the channel" do + get "/chat/#{chat_channel.id}/messages.json", params: { page_size: page_size } + expect(response.parsed_body["meta"]["channel_message_bus_last_id"]).not_to eq(nil) + end + describe "scrolling to the past" do it "returns the correct messages in created_at, id order" do get "/chat/#{chat_channel.id}/messages.json", @@ -1030,7 +1035,8 @@ RSpec.describe Chat::ChatController do }.to change { user.notifications.where(notification_type: Notification.types[:chat_invitation]).count }.by(1) - notification = user.notifications.where(notification_type: Notification.types[:chat_invitation]).last + notification = + user.notifications.where(notification_type: Notification.types[:chat_invitation]).last parsed_data = JSON.parse(notification[:data]) expect(parsed_data["chat_channel_title"]).to eq(chat_channel.title(user)) expect(parsed_data["chat_channel_slug"]).to eq(chat_channel.slug) diff --git a/plugins/chat/spec/system/hashtag_autocomplete_spec.rb b/plugins/chat/spec/system/hashtag_autocomplete_spec.rb index 203d2031f8..318e23bfb9 100644 --- a/plugins/chat/spec/system/hashtag_autocomplete_spec.rb +++ b/plugins/chat/spec/system/hashtag_autocomplete_spec.rb @@ -56,33 +56,30 @@ describe "Using #hashtag autocompletion to search for and lookup channels", expect(hashtag_results.map(&:text)).to eq(["Raspberry", "razed x 0", "Random"]) end - # TODO (martin) Commenting this out for now, we need to add the MessageBus - # last_message_id to our chat subscriptions in JS for this to work, since it - # relies on a MessageBus "sent" event to be published to substitute the - # staged message ID for the real one. - xit "cooks the hashtags for channels, categories, and tags serverside when the chat message is saved to the database" do + it "cooks the hashtags for channels, categories, and tags serverside when the chat message is saved to the database" do chat_page.visit_channel(channel1) expect(chat_channel_page).to have_no_loading_skeleton - chat_channel_page.type_in_composer("this is #random and this is #raspberry and this is #razed which is cool") + chat_channel_page.type_in_composer("this is #random and this is #raspberry-beret and this is #razed which is cool") chat_channel_page.click_send_message + message = nil try_until_success do - expect(ChatMessage.exists?(user: user, message: "this is #random and this is #raspberry and this is #razed which is cool")).to eq(true) + message = ChatMessage.find_by(user: user, message: "this is #random and this is #raspberry-beret and this is #razed which is cool") + expect(message).not_to eq(nil) end - message = ChatMessage.where(user: user).last expect(chat_channel_page).to have_message(id: message.id) within chat_channel_page.message_by_id(message.id) do cooked_hashtags = page.all(".hashtag-cooked", count: 3) expect(cooked_hashtags[0]["outerHTML"]).to eq(<<~HTML.chomp) - Random + Random HTML expect(cooked_hashtags[1]["outerHTML"]).to eq(<<~HTML.chomp) - raspberry + Raspberry HTML expect(cooked_hashtags[2]["outerHTML"]).to eq(<<~HTML.chomp) - razed + razed HTML end end diff --git a/plugins/chat/test/javascripts/acceptance/chat-browse-test.js b/plugins/chat/test/javascripts/acceptance/chat-browse-test.js index 87e91f2176..0b8e2bd8bd 100644 --- a/plugins/chat/test/javascripts/acceptance/chat-browse-test.js +++ b/plugins/chat/test/javascripts/acceptance/chat-browse-test.js @@ -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, + }, }); }); diff --git a/plugins/chat/test/javascripts/acceptance/chat-channel-info-test.js b/plugins/chat/test/javascripts/acceptance/chat-channel-info-test.js index 98c9380129..0fea5fa284 100644 --- a/plugins/chat/test/javascripts/acceptance/chat-channel-info-test.js +++ b/plugins/chat/test/javascripts/acceptance/chat-channel-info-test.js @@ -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", () => { diff --git a/plugins/chat/test/javascripts/acceptance/chat-channels-list-test.js b/plugins/chat/test/javascripts/acceptance/chat-channels-list-test.js index 4646aaa446..51f664b3c5 100644 --- a/plugins/chat/test/javascripts/acceptance/chat-channels-list-test.js +++ b/plugins/chat/test/javascripts/acceptance/chat-channels-list-test.js @@ -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, + }, }); }); diff --git a/plugins/chat/test/javascripts/acceptance/chat-live-pane-collapse-test.js b/plugins/chat/test/javascripts/acceptance/chat-live-pane-collapse-test.js index ad95b49b57..948b2b20f6 100644 --- a/plugins/chat/test/javascripts/acceptance/chat-live-pane-collapse-test.js +++ b/plugins/chat/test/javascripts/acceptance/chat-live-pane-collapse-test.js @@ -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, + }, }) ); diff --git a/plugins/chat/test/javascripts/acceptance/chat-live-pane-mobile-test.js b/plugins/chat/test/javascripts/acceptance/chat-live-pane-mobile-test.js index a7fb328d45..e07872abd8 100644 --- a/plugins/chat/test/javascripts/acceptance/chat-live-pane-mobile-test.js +++ b/plugins/chat/test/javascripts/acceptance/chat-live-pane-mobile-test.js @@ -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, + }, }) ); diff --git a/plugins/chat/test/javascripts/acceptance/chat-live-pane-silenced-user-test.js b/plugins/chat/test/javascripts/acceptance/chat-live-pane-silenced-user-test.js index 1316017f3d..06e9bd0bd6 100644 --- a/plugins/chat/test/javascripts/acceptance/chat-live-pane-silenced-user-test.js +++ b/plugins/chat/test/javascripts/acceptance/chat-live-pane-silenced-user-test.js @@ -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, + }, }) ); diff --git a/plugins/chat/test/javascripts/acceptance/chat-live-pane-test.js b/plugins/chat/test/javascripts/acceptance/chat-live-pane-test.js index c348161d78..038bf6788f 100644 --- a/plugins/chat/test/javascripts/acceptance/chat-live-pane-test.js +++ b/plugins/chat/test/javascripts/acceptance/chat-live-pane-test.js @@ -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, + }, }) ); diff --git a/plugins/chat/test/javascripts/acceptance/chat-preferences-test.js b/plugins/chat/test/javascripts/acceptance/chat-preferences-test.js index 0c6332b1b7..80ed0d4a88 100644 --- a/plugins/chat/test/javascripts/acceptance/chat-preferences-test.js +++ b/plugins/chat/test/javascripts/acceptance/chat-preferences-test.js @@ -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"); diff --git a/plugins/chat/test/javascripts/acceptance/chat-sidebar-user-status-test.js b/plugins/chat/test/javascripts/acceptance/chat-sidebar-user-status-test.js index 0cb4d62fdc..25d45bf18d 100644 --- a/plugins/chat/test/javascripts/acceptance/chat-sidebar-user-status-test.js +++ b/plugins/chat/test/javascripts/acceptance/chat-sidebar-user-status-test.js @@ -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, + }, }); }); }); diff --git a/plugins/chat/test/javascripts/acceptance/chat-transcript-test.js b/plugins/chat/test/javascripts/acceptance/chat-transcript-test.js index 00767d0071..98ff2a6b8b 100644 --- a/plugins/chat/test/javascripts/acceptance/chat-transcript-test.js +++ b/plugins/chat/test/javascripts/acceptance/chat-transcript-test.js @@ -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, + }, }) ); diff --git a/plugins/chat/test/javascripts/acceptance/core-sidebar-test.js b/plugins/chat/test/javascripts/acceptance/core-sidebar-test.js index ea3381104e..fe3968b5c9 100644 --- a/plugins/chat/test/javascripts/acceptance/core-sidebar-test.js +++ b/plugins/chat/test/javascripts/acceptance/core-sidebar-test.js @@ -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, + }, }); }); }); diff --git a/plugins/chat/test/javascripts/acceptance/create-channel-test.js b/plugins/chat/test/javascripts/acceptance/create-channel-test.js index a478f2225c..2a456ef100 100644 --- a/plugins/chat/test/javascripts/acceptance/create-channel-test.js +++ b/plugins/chat/test/javascripts/acceptance/create-channel-test.js @@ -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, + }, }) ); diff --git a/plugins/chat/test/javascripts/acceptance/delete-chat-channel-modal-test.js b/plugins/chat/test/javascripts/acceptance/delete-chat-channel-modal-test.js index 7510ae1450..48c717c273 100644 --- a/plugins/chat/test/javascripts/acceptance/delete-chat-channel-modal-test.js +++ b/plugins/chat/test/javascripts/acceptance/delete-chat-channel-modal-test.js @@ -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, + }, }); }); diff --git a/plugins/chat/test/javascripts/chat-fixtures.js b/plugins/chat/test/javascripts/chat-fixtures.js index c8ab615160..e91f5b563a 100644 --- a/plugins/chat/test/javascripts/chat-fixtures.js +++ b/plugins/chat/test/javascripts/chat-fixtures.js @@ -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 = { diff --git a/plugins/chat/test/javascripts/helpers/fabricators.js b/plugins/chat/test/javascripts/helpers/fabricators.js index a316792cba..fdc766f2c1 100644 --- a/plugins/chat/test/javascripts/helpers/fabricators.js +++ b/plugins/chat/test/javascripts/helpers/fabricators.js @@ -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, + }, }), }; diff --git a/plugins/chat/test/javascripts/unit/services/chat-test.js b/plugins/chat/test/javascripts/unit/services/chat-test.js index ebcb36da95..f08d6730da 100644 --- a/plugins/chat/test/javascripts/unit/services/chat-test.js +++ b/plugins/chat/test/javascripts/unit/services/chat-test.js @@ -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, + }, }); });