Skip to content

A platform for community discussion. Free, open, simple.

FIX: ensures thread is cleared when closing it (#21264)

Joffrey JAFFEUX7f803a033529
diff --git a/plugins/chat/assets/javascripts/discourse/routes/chat-channel-thread.js b/plugins/chat/assets/javascripts/discourse/routes/chat-channel-thread.js
index 3aa4e2b8cea..04151d5250f 100644
--- a/plugins/chat/assets/javascripts/discourse/routes/chat-channel-thread.js
+++ b/plugins/chat/assets/javascripts/discourse/routes/chat-channel-thread.js
@@ -11,6 +11,16 @@ export default class ChatChannelThread extends DiscourseRoute {
return channel.threadsManager.find(channel.id, params.threadId);
}
+ deactivate() {
+ this.#closeThread();
+ }
+
+ #closeThread() {
+ this.chat.activeChannel.activeThread?.messagesManager?.clearMessages();
+ this.chat.activeChannel.activeThread = null;
+ this.chatStateManager.closeSidePanel();
+ }
+
afterModel(model) {
this.chat.activeChannel.activeThread = model;
this.chatStateManager.openSidePanel();
diff --git a/plugins/chat/assets/javascripts/discourse/routes/chat-channel.js b/plugins/chat/assets/javascripts/discourse/routes/chat-channel.js
index f4ecc9c275f..96658d1ada4 100644
--- a/plugins/chat/assets/javascripts/discourse/routes/chat-channel.js
+++ b/plugins/chat/assets/javascripts/discourse/routes/chat-channel.js
@@ -1,26 +1,5 @@
import DiscourseRoute from "discourse/routes/discourse";
import withChatChannel from "./chat-channel-decorator";
-import { inject as service } from "@ember/service";
@withChatChannel
-export default class ChatChannelRoute extends DiscourseRoute {
- @service chat;
- @service chatStateManager;
-
- beforeModel() {
- if (this.chat.activeChannel) {
- // When moving between channels
- this.#closeThread();
- }
- }
-
- deactivate() {
- this.#closeThread();
- }
-
- #closeThread() {
- this.chat.activeChannel.activeThread?.messagesManager?.clearMessages();
- this.chat.activeChannel.activeThread = null;
- this.chatStateManager.closeSidePanel();
- }
-}
+export default class ChatChannelRoute extends DiscourseRoute {}
diff --git a/plugins/chat/spec/system/page_objects/chat/chat_side_panel.rb b/plugins/chat/spec/system/page_objects/chat/chat_side_panel.rb
index 01dfb1f2da6..fa6c15b6859 100644
--- a/plugins/chat/spec/system/page_objects/chat/chat_side_panel.rb
+++ b/plugins/chat/spec/system/page_objects/chat/chat_side_panel.rb
@@ -6,6 +6,10 @@ module PageObjects
def has_open_thread?(thread)
has_css?(".chat-side-panel .chat-thread[data-id='#{thread.id}']")
end
+
+ def has_no_open_thread?
+ !has_css?(".chat-side-panel .chat-thread")
+ end
end
end
end
diff --git a/plugins/chat/spec/system/page_objects/chat/chat_thread.rb b/plugins/chat/spec/system/page_objects/chat/chat_thread.rb
index c76e4d68945..6b744ef0439 100644
--- a/plugins/chat/spec/system/page_objects/chat/chat_thread.rb
+++ b/plugins/chat/spec/system/page_objects/chat/chat_thread.rb
@@ -11,6 +11,10 @@ module PageObjects
header.find(".chat-thread__omu")
end
+ def close
+ header.find(".chat-thread__close").click
+ end
+
def has_header_content?(content)
header.has_content?(content)
end
diff --git a/plugins/chat/spec/system/single_thread_spec.rb b/plugins/chat/spec/system/single_thread_spec.rb
index 8abb164e8d2..cf6978a42fa 100644
--- a/plugins/chat/spec/system/single_thread_spec.rb
+++ b/plugins/chat/spec/system/single_thread_spec.rb
@@ -6,8 +6,9 @@ describe "Single thread in side panel", type: :system, js: true do
let(:chat_page) { PageObjects::Pages::Chat.new }
let(:channel_page) { PageObjects::Pages::ChatChannel.new }
let(:side_panel) { PageObjects::Pages::ChatSidePanel.new }
- let(:open_thread) { PageObjects::Pages::ChatThread.new }
+ let(:thread_page) { PageObjects::Pages::ChatThread.new }
let(:chat_drawer_page) { PageObjects::Pages::ChatDrawer.new }
+ let(:sidebar_page) { PageObjects::Pages::Sidebar.new }
before do
chat_system_bootstrap(current_user, [channel])
@@ -50,6 +51,34 @@ describe "Single thread in side panel", type: :system, js: true do
before { SiteSetting.enable_experimental_chat_threaded_discussions = true }
+ context "when in full page" do
+ context "when switching channel" do
+ fab!(:channel_2) { Fabricate(:chat_channel, threading_enabled: true) }
+
+ before { channel_2.add(current_user) }
+
+ it "closes the opened thread" do
+ chat_page.visit_thread(thread)
+ expect(side_panel).to have_open_thread(thread)
+
+ sidebar_page.open_channel(channel_2)
+
+ expect(side_panel).to have_no_open_thread
+ end
+ end
+
+ context "when closing the thread" do
+ it "closes it" do
+ chat_page.visit_thread(thread)
+ expect(side_panel).to have_open_thread(thread)
+
+ thread_page.close
+
+ expect(side_panel).to have_no_open_thread
+ end
+ end
+ end
+
it "opens the single thread in the drawer using the indicator" do
visit("/latest")
chat_page.open_from_header
@@ -79,14 +108,14 @@ describe "Single thread in side panel", type: :system, js: true do
xit "shows the excerpt of the thread original message" do
chat_page.visit_channel(channel)
channel_page.message_thread_indicator(thread.original_message).click
- expect(open_thread).to have_header_content(thread.excerpt)
+ expect(thread_page).to have_header_content(thread.excerpt)
end
xit "shows the avatar and username of the original message user" do
chat_page.visit_channel(channel)
channel_page.message_thread_indicator(thread.original_message).click
- expect(open_thread.omu).to have_css(".chat-user-avatar img.avatar")
- expect(open_thread.omu).to have_content(thread.original_message_user.username)
+ expect(thread_page.omu).to have_css(".chat-user-avatar img.avatar")
+ expect(thread_page.omu).to have_content(thread.original_message_user.username)
end
describe "sending a message" do
@@ -94,8 +123,8 @@ describe "Single thread in side panel", type: :system, js: true do
chat_page.visit_channel(channel)
channel_page.message_thread_indicator(thread.original_message).click
expect(side_panel).to have_open_thread(thread)
- open_thread.send_message(thread.id, "new thread message")
- expect(open_thread).to have_message(thread.id, text: "new thread message")
+ thread_page.send_message(thread.id, "new thread message")
+ expect(thread_page).to have_message(thread.id, text: "new thread message")
thread_message = thread.replies.last
expect(thread_message.chat_channel_id).to eq(channel.id)
expect(thread_message.thread.channel_id).to eq(channel.id)
@@ -105,8 +134,8 @@ describe "Single thread in side panel", type: :system, js: true do
chat_page.visit_channel(channel)
channel_page.message_thread_indicator(thread.original_message).click
expect(side_panel).to have_open_thread(thread)
- open_thread.send_message(thread.id, "new thread message")
- expect(open_thread).to have_message(thread.id, text: "new thread message")
+ thread_page.send_message(thread.id, "new thread message")
+ expect(thread_page).to have_message(thread.id, text: "new thread message")
thread_message = thread.reload.replies.last
expect(channel_page).not_to have_css(channel_page.message_by_id_selector(thread_message.id))
end
@@ -128,19 +157,19 @@ describe "Single thread in side panel", type: :system, js: true do
using_session(:tab_2) do
expect(side_panel).to have_open_thread(thread)
- open_thread.send_message(thread.id, "the other user message")
- expect(open_thread).to have_message(thread.id, text: "the other user message")
+ thread_page.send_message(thread.id, "the other user message")
+ expect(thread_page).to have_message(thread.id, text: "the other user message")
end
using_session(:tab_1) do
expect(side_panel).to have_open_thread(thread)
- expect(open_thread).to have_message(thread.id, text: "the other user message")
- open_thread.send_message(thread.id, "this is a test message")
- expect(open_thread).to have_message(thread.id, text: "this is a test message")
+ expect(thread_page).to have_message(thread.id, text: "the other user message")
+ thread_page.send_message(thread.id, "this is a test message")
+ expect(thread_page).to have_message(thread.id, text: "this is a test message")
end
using_session(:tab_2) do
- expect(open_thread).to have_message(thread.id, text: "this is a test message")
+ expect(thread_page).to have_message(thread.id, text: "this is a test message")
end
end