A platform for community discussion. Free, open, simple.
FIX: correctly update last message bus id for threads and channels (#33846)
Joffrey JAFFEUX2d4930fe2023
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-notice.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-notice.gjsindex 55d8022ddd3..10aae3bc993 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-notice.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/chat-notice.gjs@@ -1,5 +1,6 @@import Component from "@glimmer/component";import { action } from "@ember/object";+import willDestroy from "@ember/render-modifiers/modifiers/will-destroy";import { service } from "@ember/service";import DButton from "discourse/components/d-button";import MentionWithoutMembership from "discourse/plugins/chat/discourse/components/chat/notices/mention_without_membership";@@ -21,8 +22,7 @@ export default class ChatNotices extends Component {}<template>- <div class="chat-notices__notice">-+ <div class="chat-notices__notice" {{willDestroy this.clearNotice}}>{{#if @notice.textContent}}<p class="chat-notices__notice__content">{{@notice.textContent}}diff --git a/plugins/chat/assets/javascripts/discourse/lib/chat-channel-subscription-manager.js b/plugins/chat/assets/javascripts/discourse/lib/chat-channel-subscription-manager.jsindex 30b53c77138..d6a02ef5038 100644--- a/plugins/chat/assets/javascripts/discourse/lib/chat-channel-subscription-manager.js+++ b/plugins/chat/assets/javascripts/discourse/lib/chat-channel-subscription-manager.js@@ -39,7 +39,7 @@ export default class ChatChannelSubscriptionManager {}@bind- onMessage(busData) {+ onMessage(busData, _, lastMessageBusId) {switch (busData.type) {case "sent":this.handleSentMessage(busData);@@ -81,6 +81,8 @@ export default class ChatChannelSubscriptionManager {this.handleNotice(busData);break;}++ this.channel.channelMessageBusLastId = lastMessageBusId;}handleSentMessage(data) {diff --git a/plugins/chat/assets/javascripts/discourse/lib/chat-channel-thread-subscription-manager.js b/plugins/chat/assets/javascripts/discourse/lib/chat-channel-thread-subscription-manager.jsindex 55bec2cdbfd..99fbeb75488 100644--- a/plugins/chat/assets/javascripts/discourse/lib/chat-channel-thread-subscription-manager.js+++ b/plugins/chat/assets/javascripts/discourse/lib/chat-channel-thread-subscription-manager.js@@ -37,7 +37,7 @@ export default class ChatChannelThreadSubscriptionManager {}@bind- onMessage(busData, _, __, lastMessageBusId) {+ onMessage(busData, _, lastMessageBusId) {switch (busData.type) {case "sent":this.handleSentMessage(busData);diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-channel-notices-manager.js b/plugins/chat/assets/javascripts/discourse/services/chat-channel-notices-manager.jsindex 705020c2a46..5e7c558b0b7 100644--- a/plugins/chat/assets/javascripts/discourse/services/chat-channel-notices-manager.js+++ b/plugins/chat/assets/javascripts/discourse/services/chat-channel-notices-manager.js@@ -7,10 +7,12 @@ export default class ChatChannelNoticesManager extends Service {@tracked notices = new TrackedArray();handleNotice(data) {- this.notices.pushObject(ChatNotice.create(data));+ this.notices.push(ChatNotice.create(data));}clearNotice(notice) {- this.notices.removeObject(notice);+ this.notices = new TrackedArray(+ this.notices.filter((n) => n.id !== notice.id)+ );}}diff --git a/plugins/chat/spec/system/channel_notice_spec.rb b/plugins/chat/spec/system/channel_notice_spec.rbnew file mode 100644index 00000000000..fbbaa621cb7--- /dev/null+++ b/plugins/chat/spec/system/channel_notice_spec.rb@@ -0,0 +1,52 @@+# frozen_string_literal: true++RSpec.describe "Channel notice", type: :system do+ let(:chat_page) { PageObjects::Pages::Chat.new }+ let(:channel_page) { PageObjects::Pages::ChatChannel.new }+ let(:drawer_page) { PageObjects::Pages::ChatDrawer.new }++ fab!(:current_user, :user)++ before do+ chat_system_bootstrap+ sign_in(current_user)+ end++ context "when mentioned user can't see the channel" do+ fab!(:secret_group, :group)+ fab!(:private_category) { Fabricate(:private_category, group: secret_group) }+ fab!(:private_channel) { Fabricate(:chat_channel, chatable: private_category) }+ fab!(:mentioned_user, :user)++ before do+ secret_group.add(current_user)+ private_channel.add(current_user)+ end++ it "shows the notice" do+ chat_page.visit_channel(private_channel)+ channel_page.send_message("@#{mentioned_user.username} hello")++ expect(page).to have_selector(+ ".chat-notices__notice",+ text: I18n.t("chat.mention_warning.cannot_see", first_identifier: mentioned_user.username),+ )+ end++ context "when navigating away and back to the channel" do+ it "dismisses the notice" do+ chat_page.visit_channel(private_channel)+ channel_page.send_message("@#{mentioned_user.username} hello")+ expect(page).to have_css(".chat-notices__notice")+ find("#site-logo").click+ expect(page).to have_no_css("body.has-chat")+ find(".sidebar-row.channel-#{private_channel.id}").click+ expect(drawer_page).to have_open_channel(private_channel)++ wait_for_timeout(1000) # we are waiting for message bus to update the notice++ expect(page).to have_no_css(".chat-notices__notice", wait: 0)+ end+ end+ end+enddiff --git a/plugins/chat/spec/system/page_objects/chat_drawer/chat_drawer.rb b/plugins/chat/spec/system/page_objects/chat_drawer/chat_drawer.rbindex 9404bc91a4e..6a4d4f26ff9 100644--- a/plugins/chat/spec/system/page_objects/chat_drawer/chat_drawer.rb+++ b/plugins/chat/spec/system/page_objects/chat_drawer/chat_drawer.rb@@ -119,7 +119,7 @@ module PageObjectsdef has_open_channel?(channel)has_css?("html.has-drawer-chat")- has_css?("#{VISIBLE_DRAWER} .chat-channel[data-id='#{channel.id}']")+ has_css?("#{VISIBLE_DRAWER} .chat-channel.--loaded[data-id='#{channel.id}']")enddef has_channel_settings?